Repository navigation
fix(station,wallet): remove a deleted user group from its members #675
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
Merged
+334
−5
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
faaa1d0
fix(station): remove a deleted user group from its members
claude bc910b5
feat(wallet): show the affected members when removing a user group
claude 37e41fc
fix(wallet): show the generic members warning until the members are l…
claude f5baebc
fix(wallet): show the generic members warning when no members are listed
sea-snake c9f2fa3
Merge branch 'main' into arshavir/intelligent-tesla-eif3yb
sea-snake 06aee64
Merge remote-tracking branch 'origin/main' into arshavir/intelligent-…
claude 6d560fd
Merge branch 'main' into arshavir/intelligent-tesla-eif3yb
sea-snake 9a01a9e
Merge remote-tracking branch 'origin/main' into arshavir/intelligent-…
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
apps/wallet/src/components/users/UserGroupMembersWarning.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import { flushPromises } from '@vue/test-utils'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { icAgent } from '~/core/ic-agent.core'; | ||
| import { ListUsersResult, User } from '~/generated/station/station.did'; | ||
| import { serviceManager } from '~/plugins/services.plugin'; | ||
| import { StationService } from '~/services/station.service'; | ||
| import { mount } from '~/test.utils'; | ||
| import { ExtractOk } from '~/types/helper.types'; | ||
| import UserGroupMembersWarning from './UserGroupMembersWarning.vue'; | ||
|
|
||
| vi.mock('~/services/station.service', () => { | ||
| const mock: Partial<StationService> = { | ||
| withStationId: vi.fn().mockReturnThis(), | ||
| listUsers: vi.fn().mockReturnThis(), | ||
| }; | ||
|
|
||
| return { | ||
| StationService: vi.fn(() => mock), | ||
| }; | ||
| }); | ||
|
|
||
| const mockedStationService = new StationService(icAgent.get()); | ||
| serviceManager.services.station = mockedStationService; | ||
|
|
||
| const mockListUsers = (names: string[], total = names.length) => | ||
| vi.spyOn(mockedStationService, 'listUsers').mockResolvedValueOnce({ | ||
| users: names.map(name => ({ name }) as User), | ||
| privileges: [], | ||
| next_offset: [], | ||
| total: BigInt(total), | ||
| } as ExtractOk<ListUsersResult>); | ||
|
|
||
| const mountWarning = async () => { | ||
| const wrapper = mount(UserGroupMembersWarning, { props: { userGroupId: '1' } }); | ||
| await flushPromises(); | ||
|
|
||
| return wrapper.find('[data-test-id="user-group-members-warning"]'); | ||
| }; | ||
|
|
||
| describe('UserGroupMembersWarning', () => { | ||
| it('lists the members that will be affected', async () => { | ||
| mockListUsers(['Alice', 'Bob']); | ||
|
|
||
| const warning = await mountWarning(); | ||
|
|
||
| expect(warning.text()).toContain( | ||
| 'Removing this group will affect users Alice, Bob who are still members of it.', | ||
| ); | ||
| }); | ||
|
|
||
| it('uses the singular form for a single member', async () => { | ||
| mockListUsers(['Alice']); | ||
|
|
||
| const warning = await mountWarning(); | ||
|
|
||
| expect(warning.text()).toContain( | ||
| 'Removing this group will affect user Alice who is still a member of it.', | ||
| ); | ||
| }); | ||
|
|
||
| it('mentions how many members are not listed', async () => { | ||
| mockListUsers(['Alice', 'Bob'], 5); | ||
|
|
||
| const warning = await mountWarning(); | ||
|
|
||
| expect(warning.text()).toContain('users Alice, Bob and 3 more who are still members of it.'); | ||
| }); | ||
|
|
||
| it('shows a generic warning when no members are listed', async () => { | ||
| mockListUsers([]); | ||
|
|
||
| const warning = await mountWarning(); | ||
|
|
||
| expect(warning.text()).toContain( | ||
| 'Removing this group will also remove it from any users who are still members of it.', | ||
| ); | ||
| }); | ||
|
|
||
| it('shows a generic warning when the members are not visible to the caller', async () => { | ||
| mockListUsers([], 3); | ||
|
|
||
| const warning = await mountWarning(); | ||
|
|
||
| expect(warning.text()).toContain( | ||
| 'Removing this group will also remove it from any users who are still members of it.', | ||
| ); | ||
| }); | ||
|
|
||
| it('shows a generic warning while the members are loading', async () => { | ||
| vi.spyOn(mockedStationService, 'listUsers').mockReturnValueOnce(new Promise(() => {})); | ||
|
|
||
| const warning = await mountWarning(); | ||
|
|
||
| expect(warning.text()).toContain( | ||
| 'Removing this group will also remove it from any users who are still members of it.', | ||
| ); | ||
| }); | ||
|
|
||
| it('falls back to a generic warning when the members cannot be loaded', async () => { | ||
| vi.spyOn(mockedStationService, 'listUsers').mockRejectedValueOnce(new Error('Unauthorized')); | ||
|
|
||
| const warning = await mountWarning(); | ||
|
|
||
| expect(warning.text()).toContain( | ||
| 'Removing this group will also remove it from any users who are still members of it.', | ||
| ); | ||
| }); | ||
| }); |
66 changes: 66 additions & 0 deletions
66
apps/wallet/src/components/users/UserGroupMembersWarning.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <template> | ||
| <VAlert | ||
| v-if="warning" | ||
| type="warning" | ||
| variant="tonal" | ||
| density="compact" | ||
| data-test-id="user-group-members-warning" | ||
| > | ||
| {{ warning }} | ||
| </VAlert> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { computed, onMounted, ref } from 'vue'; | ||
| import { useI18n } from 'vue-i18n'; | ||
| import { VAlert } from 'vuetify/components'; | ||
| import logger from '~/core/logger.core'; | ||
| import { UUID } from '~/generated/station/station.did'; | ||
| import { useStationStore } from '~/stores/station.store'; | ||
|
|
||
| const props = defineProps<{ | ||
| userGroupId: UUID; | ||
| }>(); | ||
|
|
||
| const MAX_LISTED_MEMBERS = 10; | ||
|
|
||
| const i18n = useI18n(); | ||
| const station = useStationStore(); | ||
|
|
||
| const memberNames = ref<string[]>([]); | ||
| const totalMembers = ref(0); | ||
| const membersLoaded = ref(false); | ||
|
|
||
| const warning = computed(() => { | ||
| // The generic warning is shown until the members are loaded, so it is never hidden while the | ||
| // confirmation is already possible, and when none are listed, since the caller might not be | ||
| // allowed to see them. | ||
| if (!membersLoaded.value || memberNames.value.length === 0) { | ||
| return i18n.t('user_groups.members_removal_warning_unknown'); | ||
| } | ||
|
|
||
| const users = memberNames.value.join(', '); | ||
| const remaining = totalMembers.value - memberNames.value.length; | ||
|
|
||
| if (remaining > 0) { | ||
| return i18n.t('user_groups.members_removal_warning_more', { users, count: remaining }); | ||
| } | ||
|
|
||
| return i18n.t('user_groups.members_removal_warning', { users }, totalMembers.value); | ||
| }); | ||
|
|
||
| onMounted(async () => { | ||
| try { | ||
| const result = await station.service.listUsers({ | ||
| groups: [props.userGroupId], | ||
| limit: MAX_LISTED_MEMBERS, | ||
| }); | ||
|
|
||
| memberNames.value = result.users.map(user => user.name); | ||
| totalMembers.value = Number(result.total); | ||
| membersLoaded.value = true; | ||
| } catch (e) { | ||
| logger.error('Failed to fetch user group members', e); | ||
| } | ||
| }); | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.