Skip to content

Commit

Permalink
Remove "Super users" from organization detail / preview page
Browse files Browse the repository at this point in the history
Changes:
- Dictionary: Rename label "Administrating positions" to "Assigned Super Users"
- Remove Super-user listing of organisation positions.
- DB-test-data: Andrew ('EF 1 Manager') is a super-user of 'EF 1' organisation.
- e2e-tests: Adapt (fix) tests

Resolves #4281
  • Loading branch information
midmarch committed Mar 20, 2023
1 parent 637a817 commit 78b409d
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 138 deletions.
4 changes: 2 additions & 2 deletions anet-dictionary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ fields:
location:
filter: [ADVISOR_LOCATION]
administratingPositions:
label: Administrating positions
label: Assigned Super Users
placeholder: Search for a position...

principal:
Expand Down Expand Up @@ -1428,7 +1428,7 @@ fields:
location:
filter: [PRINCIPAL_LOCATION]
administratingPositions:
label: Administrating positions
label: Assigned Super Users
placeholder: Search for a position...

superUser:
Expand Down
37 changes: 1 addition & 36 deletions client/src/components/previews/OrganizationPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import API from "api"
import { PreviewField } from "components/FieldHelper"
import LinkTo from "components/LinkTo"
import Model from "components/Model"
import { Organization, Position } from "models"
import { Organization } from "models"
import OrganizationLaydown from "pages/organizations/Laydown"
import OrganizationTasks from "pages/organizations/OrganizationTasks"
import PropTypes from "prop-types"
Expand Down Expand Up @@ -109,14 +109,6 @@ const OrganizationPreview = ({ className, uuid }) => {
? Settings.fields.principal.org
: Settings.fields.advisor.org

const superUsers = organization.positions.filter(
pos =>
pos.status !== Model.STATUS.INACTIVE &&
(!pos.person || pos.person.status !== Model.STATUS.INACTIVE) &&
(pos.type === Position.TYPE.SUPER_USER ||
pos.type === Position.TYPE.ADMINISTRATOR)
)

return (
<div className={`${className} preview-content-scroll`}>
<div className="preview-sticky-title">
Expand Down Expand Up @@ -156,33 +148,6 @@ const OrganizationPreview = ({ className, uuid }) => {
/>
)}

{organization.isAdvisorOrg() && (
<PreviewField
label="Super users"
value={
<React.Fragment>
{superUsers.map(position => (
<p key={position.uuid}>
{position.person ? (
<LinkTo modelType="Person" model={position.person} />
) : (
<i>
<LinkTo modelType="Position" model={position} />-
(Unfilled)
</i>
)}
</p>
))}
{superUsers.length === 0 && (
<p>
<i>No super users</i>
</p>
)}
</React.Fragment>
}
/>
)}

{organization?.childrenOrgs?.length > 0 && (
<PreviewField
label="Sub organizations"
Expand Down
5 changes: 4 additions & 1 deletion client/src/pages/organizations/Laydown.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ const OrganizationLaydown = ({ organization, refetch }) => {
)
}
>
<PositionTable positions={organization.administratingPositions} />
<PositionTable
positions={organization.administratingPositions}
id="super-user-table"
/>
<EditAdministratingPositionsModal
organization={organization}
showModal={showAdministratingPositionsModal}
Expand Down
41 changes: 1 addition & 40 deletions client/src/pages/organizations/Show.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import ReportCollection from "components/ReportCollection"
import RichTextEditor from "components/RichTextEditor"
import SubNav from "components/SubNav"
import { Field, Form, Formik } from "formik"
import { Location, Organization, Position, Report } from "models"
import { Location, Organization, Report } from "models"
import { orgTour } from "pages/HopscotchTour"
import pluralize from "pluralize"
import React, { useContext, useState } from "react"
Expand Down Expand Up @@ -215,13 +215,6 @@ const OrganizationShow = ({ pageDispatchers }) => {
? Settings.fields.principal.org
: Settings.fields.advisor.org

const superUsers = organization.positions.filter(
pos =>
pos.status !== Model.STATUS.INACTIVE &&
(!pos.person || pos.person.status !== Model.STATUS.INACTIVE) &&
(pos.type === Position.TYPE.SUPER_USER ||
pos.type === Position.TYPE.ADMINISTRATOR)
)
const myOrg =
currentUser && currentUser.position
? currentUser.position.organization
Expand Down Expand Up @@ -409,38 +402,6 @@ const OrganizationShow = ({ pageDispatchers }) => {
/>
)}

{organization.isAdvisorOrg() && (
<Field
name="superUsers"
component={FieldHelper.ReadonlyField}
label="Super users"
humanValue={
<>
{superUsers.map(position => (
<p key={position.uuid}>
{position.person ? (
<LinkTo
modelType="Person"
model={position.person}
/>
) : (
<i>
<LinkTo modelType="Position" model={position} />
- (Unfilled)
</i>
)}
</p>
))}
{superUsers.length === 0 && (
<p>
<i>No super users</i>
</p>
)}
</>
}
/>
)}

{organization.childrenOrgs &&
organization.childrenOrgs.length > 0 && (
<Field
Expand Down
55 changes: 29 additions & 26 deletions client/tests/e2e/permissions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const uuidv4 = require("uuid").v4
const test = require("../util/test")

test.serial("checking super user permissions", async t => {
test.serial("checking super-user permissions", async t => {
t.plan(13)

const {
Expand All @@ -28,8 +28,8 @@ test.serial("checking super user permissions", async t => {
const $tooltip = await $("#role_ADVISOR_tooltip")
t.regex(
await $tooltip.getAttribute("title"),
/^Super users cannot create .*$/,
"Expected tooltip for super users"
/^Super-users cannot create .*$/,
"Expected tooltip for super-users"
)

// Cancel Create Person
Expand All @@ -54,7 +54,7 @@ test.serial("checking super user permissions", async t => {

await validateUserCanEditUserForCurrentPage(t)

// User is super user, they may edit position of type super user for
// User is super-user, they may edit position of type super-user for
// the organization their position is administrating
await editAndSavePositionFromCurrentUserPage(t, true)

Expand All @@ -69,12 +69,12 @@ test.serial("checking super user permissions", async t => {

await validateUserCanEditUserForCurrentPage(t)

// User is super user, they may edit position of type super user for
// User is super-user, they may edit position of type super-user for
// the organization their position is administrating
await editAndSavePositionFromCurrentUserPage(t, true)

// User is super user, they may edit positions only for
// the organization their position is administrating
// User is super-user, they may edit positions only for
// organizations their position is assigned to
const $otherOrgPositionLink = await getFromSearchResults(
t,
"EF 1 Manager",
Expand All @@ -89,7 +89,7 @@ test.serial("checking super user permissions", async t => {
await assertElementNotPresent(
t,
".edit-position",
"super user should not be able to edit positions of the organization their position is not administrating",
"super-user should not be able to edit positions of the organization their position is not administrating",
shortWaitMs
)

Expand Down Expand Up @@ -123,28 +123,27 @@ test.serial("checking super user permissions", async t => {
await $ownOrgPositionLink.click()
await t.context.driver.wait(t.context.until.stalenessOf($ownOrgPositionLink))

await assertElementNotPresent(
t,
".edit-position",
"super user should not be able to edit positions of the organization their position is not administrating",
shortWaitMs
const $editPositionButton = await $(".edit-position")
await t.context.driver.wait(
t.context.until.elementIsVisible($editPositionButton)
)
t.pass('Jacob should be able to edit his own organization ("EF 2.2")')
})

validateUserCannotEditOtherUser(
"super user cannot edit administrator",
"super-user cannot edit administrator",
"rebecca",
"arthur",
"CIV DMIN, Arthur",
"ANET Administrator"
)

validateUserCannotEditOtherUser(
"super user cannot edit people from the organizations their position is not administrating",
"super-user cannot edit people from the organizations their position is not administrating",
"jacob",
"rebecca",
"CTR BECCABON, Rebecca",
"EF 2.2 Final Reviewer"
"andrew",
"CIV ANDERSON, Andrew",
"EF 1 Manager"
)

test.serial("checking regular user permissions", async t => {
Expand Down Expand Up @@ -175,7 +174,7 @@ test.serial("checking regular user permissions", async t => {
})

validateUserCannotEditOtherUser(
"Regular user cannot edit super user people or positions",
"Regular user cannot edit super-user people or positions",
"jack",
"rebecca",
"CTR BECCABON, Rebecca",
Expand Down Expand Up @@ -234,12 +233,14 @@ test.serial("checking admin permissions", async t => {

await t.context.pageHelpers.clickMenuLinksButton()
await t.context.pageHelpers.clickMyOrgLink()
const $arthurLink = await findSuperUserLink(t, "CIV DMIN, Arthur")
await $arthurLink.click()
await t.context.driver.wait(t.context.until.stalenessOf($arthurLink))

const element = await t.context.driver.findElement(
By.linkText("CIV DMIN, Arthur")
)
await element.click()

await validateUserCanEditUserForCurrentPage(t)
// User is admin, and can therefore edit an admin position type
// User is admin, and can therefore edit (its own) admin position type
await editAndSavePositionFromCurrentUserPage(t, true)

const $principalOrgLink = await getFromSearchResults(
Expand Down Expand Up @@ -278,7 +279,7 @@ test.serial("admins can edit superusers and their positions", async t => {
await t.context.driver.wait(t.context.until.stalenessOf($rebeccaPersonLink))
await validateUserCanEditUserForCurrentPage(t)

// User is admin, and can therefore edit a super user position type
// User is admin, and can therefore edit a super-user position type
await editAndSavePositionFromCurrentUserPage(t, true)

await t.context.logout()
Expand Down Expand Up @@ -332,7 +333,9 @@ function validateUserCannotEditOtherUser(
}

async function findSuperUserLink(t, desiredSuperUserName) {
const $superUserLinks = await t.context.$$("[name=superUsers] p a")
const $superUserLinks = await t.context.$$(
"[id=super-user-table] tbody tr td:nth-child(4) span a"
)
let $foundLink
for (const $superUserLink of $superUserLinks) {
const superUserName = await $superUserLink.getText()
Expand Down Expand Up @@ -424,7 +427,7 @@ async function validateSuperUserPrincipalOrgPermissions(t) {
await assertElementNotPresent(
t,
"#editButton",
"Super users should not be able to edit principal organizations",
"Super-users should not be able to edit principal organizations",
shortWaitMs
)
}
Expand Down
Loading

0 comments on commit 78b409d

Please sign in to comment.