-
-
Notifications
You must be signed in to change notification settings - Fork 956
Migrate the facility plugin to the new resource methods #15184
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
AlexVelezLl
merged 8 commits into
learningequality:develop
from
rtibblesbot:issue-15062-fbe9fc
Aug 17, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
514c830
Move facility resource calls onto the new Resource methods
rtibblesbot e0e4302
Rewrite DeletedFacilityUserResource.restoreCollection onto request
rtibblesbot d4e3e4f
Read facility users through useList
rtibblesbot c3d6507
Delete the unused plugin-local PortalResource
rtibblesbot 87999a9
Return each user once from the facility user relation filters
rtibblesbot dd68192
Read the user back instead of patching nothing on a role-only change
rtibblesbot 1d17217
Keep the settings snapshot until both halves of the save are done
rtibblesbot ae36409
Apply review-cycle changes with no owning commit
rtibblesbot 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
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 was deleted.
Oops, something went wrong.
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
72 changes: 72 additions & 0 deletions
72
kolibri/plugins/facility/frontend/composables/__tests__/useUserManagement.spec.js
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,72 @@ | ||
| import { nextTick } from 'vue'; | ||
| import client from 'kolibri/client'; | ||
| import { error as appError, clearError } from 'kolibri/utils/appError'; | ||
| import { useRoute, useRouter } from 'vue-router/composables'; | ||
| import useUserManagement from '../useUserManagement'; | ||
|
|
||
| jest.mock('kolibri/client'); | ||
| jest.mock('kolibri/urls'); | ||
| jest.mock('vue-router/composables'); | ||
|
|
||
| const SERVER_ERROR_MESSAGE = 'Request failed with status code 500'; | ||
|
|
||
| describe('useUserManagement', () => { | ||
| let router; | ||
|
|
||
| function setup({ query = {} } = {}) { | ||
| router = { push: jest.fn() }; | ||
| useRoute.mockReturnValue({ query }); | ||
| useRouter.mockReturnValue(router); | ||
| return useUserManagement({ activeFacilityId: 'facility-1' }); | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| client.__reset(); | ||
| clearError(); | ||
| }); | ||
|
|
||
| it('exposes the paginated response as mapped users and page counts', async () => { | ||
| client.__setPayload({ | ||
| results: [{ id: 'user-1', full_name: 'Test User', facility: 'facility-1', roles: [] }], | ||
| count: 1, | ||
| total_pages: 3, | ||
| }); | ||
|
|
||
| const { fetchUsers, facilityUsers, usersCount, totalPages } = setup(); | ||
| await fetchUsers(); | ||
|
|
||
| expect(facilityUsers.value).toEqual([ | ||
| expect.objectContaining({ id: 'user-1', full_name: 'Test User', facility_id: 'facility-1' }), | ||
| ]); | ||
| expect(usersCount.value).toBe(1); | ||
| expect(totalPages.value).toBe(3); | ||
| }); | ||
|
|
||
| it('falls back to the first page when a stale page number 404s', async () => { | ||
| // A bare `status`, not an axios-shaped error: the composable branches on `error.status`, and | ||
| // `logError` only stays quiet while `config` and `response` are both absent. | ||
| client.mockRejectedValue({ status: 404 }); | ||
|
|
||
| const { fetchUsers } = setup({ query: { page: '2' } }); | ||
| await fetchUsers(); | ||
| // The handler is a watcher on the `error` ref, so the awaited fetch alone does not reach it. | ||
| await nextTick(); | ||
|
|
||
| expect(router.push).toHaveBeenCalledWith( | ||
| expect.objectContaining({ query: expect.objectContaining({ page: 1 }) }), | ||
| ); | ||
| expect(appError.value).toBeNull(); | ||
| }); | ||
|
|
||
| it('reports any other failure without throwing out of the watcher', async () => { | ||
| client.mockRejectedValue({ status: 500, message: SERVER_ERROR_MESSAGE }); | ||
|
|
||
| const { fetchUsers } = setup(); | ||
| await fetchUsers(); | ||
| await nextTick(); | ||
|
|
||
| // A throw from the watcher hits Vue's error handler, which the suite's console rules fail on. | ||
| expect(appError.value).toContain(SERVER_ERROR_MESSAGE); | ||
| expect(router.push).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
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.