Giter Club home page Giter Club logo

Comments (9)

xispa avatar xispa commented on July 3, 2024 2

You are right @toropok . If the client does not have the permission senaite.core: Transition: Receive granted, the sample should transition to sample_due. With the if-else above, the sample won't transition otherwise, but remain in registered status. Will open another PR

from senaite.core.

ramonski avatar ramonski commented on July 3, 2024

Hi @toropok,
thanks for reporting your findings in this issue!

The code above is not the right solution to this problem, because also a client contact might have the permission granted to receive a sample.

The right solution is rather to pass in check_permission=True to the receive_sample function in line 145.

Can you check if this solves your issue?

from senaite.core.

ramonski avatar ramonski commented on July 3, 2024

Hmm, it seems like the permission check does not work for the temporary sample at this stage.
Maybe it is sufficient for this functionality to check if the current user has the LabManager role instead of checking the permission of on the object itself.

from senaite.core.

ramonski avatar ramonski commented on July 3, 2024

For the records:

With #2359 we increased the performance for the sample create process by changing the initial workflow state of samples from sample_registered to sample_due or sample_received directly and bypass the transition.

Due to this change, we also move from sample_registered -> sample_received directly.

However, at the state sample_registered, we do not allow any permissions.
Therefore, a permission check for senaite.core: Transition: Receive Sample will always return false, no matter which role the current user has.

Also see the comment in the code at https://github.com/senaite/senaite.core/blob/2.x/src/bika/lims/utils/analysisrequest.py#L179-L187:

def receive_sample(sample, check_permission=False, date_received=None):
    """Receive the sample without transition
    """
    # NOTE: In `sample_registered` state we do not grant any roles the
    #       permission to receive a sample! Not sure if this can be ignored
    #       when the LIMS is configured to auto-receive samples?
    if check_permission and not can_receive(sample):
        return False
    ...

This leaves us with the following options:

  1. Grant the permission senaite.core: Transition: Receive Sample at the state sample_registererd to the default roles.
  2. Check just the roles of the current user and allow only e.g. LabManager and LabClerk to receive the sample.
  3. Check the default roles for the permission senaite.core: Transition: Receive Sample and check if the current user has one of these roles granted.

from senaite.core.

xispa avatar xispa commented on July 3, 2024

I vote fot the first option, grant the senaite.core: Transition: Receive Sample at the state sample_registered to the default roles. At least it feels less an exception to the norm.

from senaite.core.

xispa avatar xispa commented on July 3, 2024

Another option would be to "always" try the transition, without the need of checking the value for the setting at setup. And let the mutator of the setup settint to grant/revoke the permission for default roles in sample_workflow and registered status.

from senaite.core.

ramonski avatar ramonski commented on July 3, 2024

It should be fixed with #2419
Please check @toropok and give feedback if this works for your use case as well.

from senaite.core.

toropok avatar toropok commented on July 3, 2024

It should be fixed with #2419 Please check @toropok and give feedback if this works for your use case as well.

@ramonski im sorry for long waiting. Please, check our microfix below (line 144), this makes it work amazing :) just as before for our use-case.

With the code you proposed, when client create sample it appears to be in "Registered" state. However if I understand this if-elif-else block properly the result state should be "sample due".

    if not IReceived.providedBy(ar):
        setup = api.get_setup()
        # Sampling is required
        if ar.getSamplingRequired():
            changeWorkflowState(ar, SAMPLE_WORKFLOW, "to_be_sampled",
                                action="to_be_sampled")
        elif setup.getAutoreceiveSamples() and can_receive(ar):
            receive_sample(ar)
        else:
            changeWorkflowState(ar, SAMPLE_WORKFLOW, "sample_due",
                                action="no_sampling_workflow")

thanks a lot for your time and attention!

from senaite.core.

toropok avatar toropok commented on July 3, 2024

thanks guys!

from senaite.core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.