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

UIIN-2452: Enable/disable consortial holdings/item actions based on User permissions #2284

Merged
merged 45 commits into from
Oct 20, 2023

Conversation

OleksandrHladchenko1
Copy link
Contributor

@OleksandrHladchenko1 OleksandrHladchenko1 commented Oct 3, 2023

Purpose

  • In a consortium environment, Instance records may contain holdings from multiple institutions and users from one library may need to evaluate materials that are held by different institutions.
  • Users in a central consortial environment should be able to view holdings and items for all member libraries, and depending on permissions, also create and edit holdings and items.
  • Users in a local member library should be able to view their own holdings and items first, followed by other consortial member library holdings and items.

Approach

  • Added tenantId parameter to useBoundWithHoldings to dynamically change X-Okapi-Tenant header
  • In ViewInstance component we fetch all the assigned permissions of all user's tenants using getUserTenantsPermissions function
  • In getCurrentTenantPermissions function we get all the assigned permissions of all user's tenants if isUserInConsortiumModed === true otherwise we get just all user's permissions
  • Added isViewHoldingsDisabled and isAddItemDisabled props to HoldingButtonsGroup component to disable "View Holdings" and "Add item" buttons when member tenant doesn't have permissions
  • Added isBarcodeAsHotlink prop to ItemBarcode component to display barcode as a hotlink or not depends on user's permission
  • Added disabled prop to InstanceNewHolding component to disable "Add holding" button if user doesn't have permissions
  • In order to update affiliation correctly, replaced Link component with Button and added styles so it behaves as a hotlink
  • When user wants to view or create Item/Holding we call updateAffiliation function to switch affiliations if user in on the other member tenant.
  • Updated and added unit tests

Refs

UIIN-2452

Screenshots

UIIN-2452.mp4

@github-actions
Copy link

github-actions bot commented Oct 3, 2023

Jest Unit Test Statistics

    1 files  ±0  226 suites  ±0   11m 49s ⏱️ +42s
887 tests +7  885 ✔️ +7  2 💤 ±0  0 ±0 
892 runs  +7  890 ✔️ +7  2 💤 ±0  0 ±0 

Results for commit e81a420. ± Comparison against base commit 306b510.

♻️ This comment has been updated with latest results.

@OleksandrHladchenko1 OleksandrHladchenko1 changed the title UI in 2452 UIIN-2452: Enable/disable consortial holdings/item actions based on User permissions Oct 9, 2023
@OleksandrHladchenko1 OleksandrHladchenko1 marked this pull request as ready for review October 9, 2023 10:43
Copy link
Contributor

@BogdanDenis BogdanDenis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @zburke that potentially validateUser could be used to re-load modules without page reload.
For this though some modifications need to be made to that function, because validateUser takes tenant from current session
https://github.com/folio-org/stripes-core/blob/master/src/loginServices.js#L411

If we're going to continue with page reload - please create a tech debt story and add TODO comments where that reload happens to explain why the reload is needed and link the tech debt story

@zburke
Copy link
Member

zburke commented Oct 17, 2023

For this though some modifications need to be made to that function, because validateUser takes tenant from current session

That's true, @BogdanDenis, but that feels like a bug: I expected validateUser() to use the tenant it is given and only pull from the session if no argument is specified, similar to the useOkapiKy implementation in #1348. In fact it's the reverse, using the value pulled from the session by default and only accepting the argument if the session's value is empty. That's puzzling given that createOkapiSession always stores a value for tenant in the session, so I can't come up with any circumstance when validateUser() would use its argument.

@NikitaSedyx, can you provide some context for why it was written this way since it seems deliberate? It would be nice to reuse validateUser() if possible, but if we have different needs (sometimes we want the value from storage to be the default, sometimes we want a specific value to be the default) then we can copy-and-tweak the existing function.

src/Holding/CreateHolding/CreateHolding.js Outdated Show resolved Hide resolved
src/Instance/InstanceDetails/InstanceDetails.js Outdated Show resolved Hide resolved
src/Item/CreateItem/CreateItem.js Outdated Show resolved Hide resolved
src/routes/ItemRoute.js Outdated Show resolved Hide resolved
src/utils.js Outdated Show resolved Hide resolved
src/Instance/InstanceDetails/InstanceDetails.test.js Outdated Show resolved Hide resolved
src/utils.test.js Outdated Show resolved Hide resolved
src/utils.js Show resolved Hide resolved
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

76.9% 76.9% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@OleksandrHladchenko1 OleksandrHladchenko1 merged commit 90f2bff into master Oct 20, 2023
3 of 4 checks passed
@OleksandrHladchenko1 OleksandrHladchenko1 deleted the UIIN-2452 branch October 20, 2023 12:11
mariia-aloshyna pushed a commit that referenced this pull request Nov 7, 2023
…ser permissions (#2284)

* Consortial holdings acc

* UIIN-2410: Adjustments

* UIIN-2410: Add new hook

* UIIN-2410: Add tests

* UIIN-2452: Disable buttons when member tenant does not have permissions

* UIIN-2410: Instance 3rd pane: Add consortial holdings/item accordion

* UIIN-2452: Add unit tests & switching affiliation when view holdings and add item

* UIIN-2410: Fix tests

* UIIN-2452: Add switching affiliation when click on item barcode & Add holdings button

* UIIN-2452: Fix tests

* Update HoldingAccordion.js

* Update HoldingButtonsGroup.js

* UIIN-2452: Fix tests

* Update HoldingsListMovement.js

* Update HoldingContainer.js

* UIIN-2452: Add returning to the previous affiliation

* UIIN-2452: Add tenantId to props validation

* UIIN-2452: Add behaviour for non-consortial tenant

* Fix some comments

* Fix perms handling

* Fix warnings

* Adjust tests

* Fix tests

* UIIN-2452: Switch user affiliation using validateUser

* Update HoldingAccordion.js

* Supress Add holding & Add item & View holdings buttons if user doesn't have permissions

* UIIN-2452: Fix comments & add unit tests

* UIIN-2452: Fixes after review

* UIIN-2452: Fix code smells

---------

Co-authored-by: Mariia_Aloshyna <[email protected]>
Co-authored-by: Mariia Aloshyna <[email protected]>
(cherry picked from commit 90f2bff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants