Merge pull request #14498 from overleaf/ab-fix-managed-user-admin

[web] Do not show Delete user button for managed group admin

GitOrigin-RevId: 4fcb120e6feec51c218cce7f381925eb12680afd
This commit is contained in:
Alexandre Bourdin 2023-08-25 11:24:58 +02:00 committed by Copybot
parent 15f26eb622
commit 0ae6adb4d6
2 changed files with 50 additions and 5 deletions

View file

@ -173,7 +173,11 @@ export default function ManagedUserDropdownButton({
) : null}
</MenuItemButton>
) : null}
{user.enrollment?.managedBy ? (
{user.isEntityAdmin ? (
<MenuItem data-testid="no-actions-available">
<span className="text-muted">{t('no_actions')}</span>
</MenuItem>
) : user.enrollment?.managedBy ? (
<MenuItemButton
className="delete-user-action"
data-testid="delete-user-action"
@ -181,10 +185,6 @@ export default function ManagedUserDropdownButton({
>
{t('delete_user')}
</MenuItemButton>
) : user.isEntityAdmin ? (
<MenuItem data-testid="no-actions-available">
<span className="text-muted">{t('no_actions')}</span>
</MenuItem>
) : (
<MenuItemButton
onClick={onRemoveFromGroup}

View file

@ -139,4 +139,49 @@ describe('ManagedUserDropdownButton', function () {
cy.findByTestId('no-actions-available').should('exist')
})
})
describe('with managed group admin user', function () {
const user = {
_id: 'some-user',
email: 'some.user@example.com',
first_name: 'Some',
last_name: 'User',
invite: false,
last_active_at: new Date(),
enrollment: {
managedBy: 'some-group',
enrolledAt: new Date(),
},
isEntityAdmin: true,
}
beforeEach(function () {
cy.window().then(win => {
win.metaAttributesCache.set('ol-users', [user])
})
cy.mount(
<GroupMembersProvider>
<ManagedUserDropdownButton
user={user}
openOffboardingModalForUser={sinon.stub()}
groupId={subscriptionId}
setManagedUserAlert={sinon.stub()}
/>
</GroupMembersProvider>
)
})
it('should render the button', function () {
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
'exist'
)
cy.get(`.action-btn`).should('exist')
})
it('should show the (empty) menu when the button is clicked', function () {
cy.get('.action-btn').click()
cy.findByTestId('no-actions-available').should('exist')
})
})
})