hyrax icon indicating copy to clipboard operation
hyrax copied to clipboard

Fix visibility prompt bug

Open abelemlih opened this issue 9 months ago • 1 comments

Fixes

Fixes #6537

Summary

When saving a work in Sirenia, users consistently receive a prompt to verify changes to visibility, even when they did not make any edits to visibility. This is due to an underlying bug in comparing saved permissions with new permissions.

Guidance for testing, such as acceptance criteria or new user interface behaviors:

  1. Login as an Admin user
  2. Go to Dashboard > Works > All Works
  3. Edit a work deposited by a different user OR a work you deposited
  4. Make a minor metadata-only edit somewhere in the Description tab (do not adjust Visibility)
  5. Save the changes
  6. Verify that you cannot see the prompt to "Apply changes to contents? You have changed the access level..."

Type of change (for release notes)

  • notes-bugfix Bug Fixes

Detailed Description

the underlying problem is in this method in app/controllers/concerns/hyrax/works_controller_behavior.rb:

def permissions_changed?
      @saved_permissions !=
        case curation_concern
        when ActiveFedora::Base
          curation_concern.permissions.map(&:to_hash)
        else
          Hyrax::AccessControl.for(resource: curation_concern).permissions
        end
end

when using Valkyrie, the array comparison between @saved_permissions and Hyrax::AccessControl.for(resource: curation_concern).permissions is always returning false even when permissions are exactly the same, because order in the two arrays is not always the same.

Changes proposed in this pull request:

  • Replace comparing arrays with comparing array sizes and checking that each permission in the new permissions array exists in the saved permissions set

@samvera/hyrax-code-reviewers

abelemlih avatar May 17 '24 20:05 abelemlih