Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when creating a partition as analyst user #1525

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Changelog

**Fixed**

- #1525 Fix error when creating partitions with analyst user
- #1522 Fix sporadical timeout issue when adding new samples/remarks
- #1506 Changes via manage results don't get applied to partitions
- #1506 Fix recursion error when getting dependencies through Calculation
Expand Down
3 changes: 1 addition & 2 deletions bika/lims/browser/analysisrequest/analysisrequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,7 @@ def get_progress_percentage(self, ar_brain):
@property
def copy_to_new_allowed(self):
mtool = api.get_tool("portal_membership")
if mtool.checkPermission(ManageAnalysisRequests, self.context) \
or mtool.checkPermission(ModifyPortalContent, self.context):
if mtool.checkPermission(AddAnalysisRequest, self.context):
return True
return False

Expand Down
2 changes: 1 addition & 1 deletion bika/lims/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
for="*"
name="partition_magic"
class=".partition_magic.PartitionMagicView"
permission="senaite.core.permissions.ManageAnalysisRequests"
permission="senaite.core.permissions.AddAnalysisRequest"
layer="bika.lims.interfaces.IBikaLIMS"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1283,16 +1283,14 @@
</guard>
</transition>

<!-- Transition: create_partitions
TODO: Consider to add "Transition: Add Partition" permission (~ "Add Sample"?)
-->
<!-- Transition: create_partitions -->
<transition transition_id="create_partitions" title="Create partitions"
new_state="sample_received" trigger="USER"
before_script="" after_script=""
i18n:attributes="title">
<action url="" category="workflow" icon="">Create partitions</action>
<guard>
<guard-permission>senaite.core: Edit Results</guard-permission>
<guard-permission>senaite.core: Add AnalysisRequest</guard-permission>
<guard-expression>python:here.guard_handler("create_partitions")</guard-expression>
</guard>
</transition>
Expand Down
25 changes: 25 additions & 0 deletions bika/lims/upgrade/v01_03_003.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ def upgrade(tool):
# https://github.com/senaite/senaite.core/pull/1517
install_senaite_core_spotlight(portal)

# Don't allow Analysts to create partitions
setup.runImportStepFromProfile(profile, "workflow")
update_wf_received_samples(portal)

# apply resource profiles
setup.runImportStepFromProfile(profile, "jsregistry")
setup.runImportStepFromProfile(profile, "cssregistry")
Expand Down Expand Up @@ -723,3 +727,24 @@ def remove_stale_css(portal):
for css in CSS_TO_REMOVE:
logger.info("Unregistering CSS %s" % css)
portal.portal_css.unregisterResource(css)


def update_wf_received_samples(portal):
"""Updates workflow mappings for root samples that are in received status
"""
logger.info("Updating workflow mappings for received samples ...")
wf_tool = api.get_tool("portal_workflow")
sample_workflow = wf_tool.getWorkflowById("bika_ar_workflow")
query = dict(portal_type="AnalysisRequest",
isRootAncestor=True,
review_state="received")
brains = api.search(query, CATALOG_ANALYSIS_REQUEST_LISTING)
total = len(brains)
for num, brain in enumerate(brains):
if num and num % 1000 == 0:
logger.info("{}/{} samples processed ...".format(num, total))
sample = api.get_object(brain)
sample_workflow.updateRoleMappingsFor(sample)
sample.reindexObject()

logger.info("Updating workflow mappings for received samples [DONE]")