samvera / hyrax

Hyrax is a Ruby on Rails Engine built by the Samvera community. Hyrax provides a foundation for creating many different digital repository applications.
http://hyrax.samvera.org/
Apache License 2.0
184 stars 124 forks source link

Notifications for reviewer role going beyond the admin set #936

Closed laritakr closed 7 years ago

laritakr commented 7 years ago

Descriptive summary

Anyone with reviewer role on an admin set is getting the notifications for works submitted on ALL admin sets. This issue exists in both the 1-0 stable and the master branch.

Rationale

Users with the approving role should only get useful notifications.

Expected behavior

Anyone with the workflow role of reviewer on an admin set should be notified of works submitted to that admin set which they should review.

Actual behavior

Anyone with the workflow role of reviewer on any admin set are getting notifications of works submitted to all admin sets.

Steps to reproduce the behavior

I created two separate admin sets and 6 users with varying participant roles and workflow roles, and submitted works from each user who was able to submit to each admin set. Reviewers for only admin set 1 received notifications for works submitted to both admin sets.

Spreadsheet of users, roles, and what they were able to do in the app.

jcoyne commented 7 years ago

Possibly returning wrong values here: https://github.com/samvera/hyrax/blob/master/app/services/hyrax/workflow/notification_service.rb#L50

dazza-codes commented 7 years ago

I like to see the SQL for https://github.com/samvera/hyrax/blob/master/app/services/hyrax/workflow/permission_query.rb#L266-L271 so this snippet was taken from one of the specs using sub_query_for_user.to_sql:

SELECT CAST("sipity_agents"."proxy_for_id" AS integer)
FROM "sipity_agents"
WHERE (
    "sipity_agents"."id" IN (
        SELECT "sipity_workflow_responsibilities"."agent_id"
        FROM "sipity_workflow_responsibilities"
        WHERE "sipity_workflow_responsibilities"."workflow_role_id" IN (
            SELECT "sipity_workflow_roles"."id"
            FROM "sipity_workflow_roles"
            WHERE "sipity_workflow_roles"."role_id" IN (1)
        )
      ) OR "sipity_agents"."id" IN (
        SELECT "sipity_entity_specific_responsibilities"."agent_id"
        FROM "sipity_entity_specific_responsibilities"
        WHERE "sipity_entity_specific_responsibilities"."workflow_role_id" IN (
            SELECT "sipity_workflow_roles"."id"
            FROM "sipity_workflow_roles"
            WHERE "sipity_workflow_roles"."role_id" IN (1)
        ) AND "sipity_entity_specific_responsibilities"."entity_id" = '1'
      )
) AND "sipity_agents"."proxy_for_type" = 'User'

It difficult to identify an AdminSet entity in this query. It seems the use of the sipity_workflow_responsibilities and sipity_workflow_roles might be global things, whereas the sipity_entity_specific_responsibilities is specific to an "entity", and these two things are combined with an OR relation. Perhaps what we need is a WHERE with an AND instead of an OR to combine the sipity_workflow_responsibilities and the sipity_entity_specific_responsibilities, but the entity must be the AdminSet that a new Work belongs to. But I'm totally guessing at this point, because I don't understand how sipity_workflow_responsibilities and and sipity_workflow_roles correspond to user management roles for an AdminSet.

mjgiarlo commented 7 years ago

@darrenleeweber You're right that this query doesn't involve AdminSets at all. The Sipity internals work independent of AdminSets, and we have yet to reconcile the two models for assigning roles (the ones defined in Sipity workflows, and the ones used for AdminSets). The Notre Dame team has been working on some documentation that will unify/clarify the roles used within Hyrax. @laritakr has been a key player there.

It's complicated further by the fact that the roles defined in the default workflows bundled with Hyrax map cleanly to the AdminSet roles, but downstream users are free to define their own roles that do not map cleanly to AdminSets.

Tagging in @jeremyf and @jcoyne, the two folks who best understand this particular module.

dazza-codes commented 7 years ago

I’ll try to note how I understand the problem, at the moment, for the workflow permission problem:

In this issue, the “expected behavior” is: Anyone with the workflow role of reviewer on an admin set should be notified of works submitted to that admin set which they should review.

So, it seems like the “expected behavior” is requesting something that is not in the Sipity design; that is, it wants a combination of a WorkflowResponsibility and an EntitySpecificResponsibility. In other words, the issue requests something like an EntitySpecificWorkflowResponsibility. Perhaps this can be defined as all the Agents who must have a Responsibility in both the WorkflowResponsibility and the EntitySpecificResponsibility when the Entity is an AdminSet and when the Workflow is "adding a work to the admin set".

Moreover, it might require a complex definition of Entity that involves a parent-child relationship between an AdminSet and all the Works that are associated with it. Maybe this involves definition of a specific workflow that is just "add work to admin set"?

Also, I’m starting to wonder whether this might require dynamic creation of a new Workflow that is specific to an AdminSet. That is, the workflow will be a record in the workflows table and it will be prefixed with some identifier that connects it to a specific Entity, i.e. the AdminSet. This results in a proliferation of workflows.

This is likely some kind of UI features for dynamic selection/creation of workflows on an AdminSet entity and somehow define how each User/Role on the AdminSet is attached to the workflow. The manager of the admin set can choose pre-existing generic workflows or create a new one based on the generic options or create a new one from scratch.

dazza-codes commented 7 years ago

Notes on reproducing the bug noted in this issue: