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

feat(organizations): add functions for managing members TASK-985 #5281

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e17f6a7
Add endpoints to handle organization members
rajpatel24 Nov 6, 2024
024f911
Merge branch 'main' of github.com:kobotoolbox/kpi into task-963-creat…
rajpatel24 Nov 7, 2024
56cd7cf
add initial files for organization members route (WIP)
magicznyleszek Nov 12, 2024
95e48c4
pass org id to hook (WIP)
magicznyleszek Nov 12, 2024
0401fc4
Refactor organization member API to eliminate redundancy and optimize…
rajpatel24 Nov 13, 2024
1dec6eb
Merge branch 'main' into task-963-create-endpoints-to-handle-org-members
rajpatel24 Nov 13, 2024
99eea0c
Add `queryHookOptions` to `PaginatedQueryUniversalTable` to make the …
magicznyleszek Nov 13, 2024
9527848
Merge branch 'main' into leszek/task-980-members-table
magicznyleszek Nov 13, 2024
a75ca3b
add initial files for organization members route (WIP)
magicznyleszek Nov 12, 2024
f2301b7
pass org id to hook (WIP)
magicznyleszek Nov 12, 2024
2066a3b
Add `queryHookOptions` to `PaginatedQueryUniversalTable` to make the …
magicznyleszek Nov 13, 2024
864e244
style(universalTable) use Array<T> for columns prop (#5260)
magicznyleszek Nov 13, 2024
47f6cf1
Merge branch 'leszek/task-980-members-table' of github.com:kobotoolbo…
magicznyleszek Nov 13, 2024
1f1cc12
small fixes (WIP)
magicznyleszek Nov 13, 2024
3c174df
Add role-based validation tests for organization member permissions
rajpatel24 Nov 14, 2024
f432404
Merge branch 'main' into task-963-create-endpoints-to-handle-org-members
rajpatel24 Nov 14, 2024
d876fbc
Revert unintended change and fix linting issue
rajpatel24 Nov 14, 2024
89721fe
Merge branch 'task-963-create-endpoints-to-handle-org-members' into l…
magicznyleszek Nov 15, 2024
953b716
Refactor organization members API with updated permission logic and c…
rajpatel24 Nov 15, 2024
f8cb95b
Refactor organization members API with updated permission logic and c…
rajpatel24 Nov 15, 2024
3d0372a
Resolve merge conflicts
rajpatel24 Nov 15, 2024
906be3d
Fix failing tests
rajpatel24 Nov 15, 2024
d122576
Merge branch 'main' into task-963-create-endpoints-to-handle-org-members
rajpatel24 Nov 18, 2024
837c1ac
adjust MembersRoute table column sizes
magicznyleszek Nov 19, 2024
1222115
Merge branch 'task-963-create-endpoints-to-handle-org-members' into l…
magicznyleszek Nov 19, 2024
08bc12e
display badges in MembersRoute table and remove some WIP code
magicznyleszek Nov 19, 2024
78a4b51
Merge branch 'leszek/task-980-members-table' of github.com:kobotoolbo…
magicznyleszek Nov 19, 2024
94b47cb
Merge branch 'main' into task-963-create-endpoints-to-handle-org-members
magicznyleszek Nov 19, 2024
adf5cad
Merge branch 'task-963-create-endpoints-to-handle-org-members' into l…
magicznyleszek Nov 19, 2024
696bef0
Merge branch 'leszek/task-980-members-table' of github.com:kobotoolbo…
magicznyleszek Nov 19, 2024
01c189c
Update delete logic to remove user from user table along with organiz…
rajpatel24 Nov 19, 2024
89db1d1
Merge branch 'main' into task-963-create-endpoints-to-handle-org-members
magicznyleszek Nov 19, 2024
42d4f23
Merge branch 'task-963-create-endpoints-to-handle-org-members' into l…
magicznyleszek Nov 19, 2024
b5ccac7
add some comments
magicznyleszek Nov 19, 2024
3ea9420
add missing semicolon
magicznyleszek Nov 19, 2024
988b10b
Merge branch 'main' into task-963-create-endpoints-to-handle-org-members
magicznyleszek Nov 19, 2024
4951a1c
Merge branch 'task-963-create-endpoints-to-handle-org-members' into l…
magicznyleszek Nov 19, 2024
ac80999
use latest Avatar version in the table
magicznyleszek Nov 19, 2024
e5688a3
add functions for updating and removing organization member
magicznyleszek Nov 19, 2024
e5abfa0
Merge branch 'main' into task-963-create-endpoints-to-handle-org-members
magicznyleszek Nov 19, 2024
19d1b6a
Merge branch 'task-963-create-endpoints-to-handle-org-members' into l…
magicznyleszek Nov 19, 2024
7672143
Use useOrganizationQuery directly in useOrganizationMembersQuery
jamesrkiger Nov 19, 2024
c20c0f4
remove queryHookOptions from PaginatedQueryUniversalTable
magicznyleszek Nov 19, 2024
f250c27
add helpful comment
magicznyleszek Nov 20, 2024
7afa649
Merge branch 'leszek/task-980-members-table' into leszek/task-985-mem…
magicznyleszek Nov 20, 2024
4f0f55a
update comments
magicznyleszek Nov 20, 2024
1389d6e
Merge branch 'leszek/task-980-members-table' into leszek/task-985-mem…
magicznyleszek Nov 20, 2024
def1a7a
Refactor permissions to block external users from listing organizatio…
rajpatel24 Nov 20, 2024
c2cf803
Merge branch 'main' into task-963-create-endpoints-to-handle-org-members
magicznyleszek Nov 20, 2024
8c7ed27
Merge branch 'task-963-create-endpoints-to-handle-org-members' into l…
magicznyleszek Nov 20, 2024
40ca814
use OrganizationUserRole in membersQuery
magicznyleszek Nov 20, 2024
500df96
Merge branch 'leszek/task-980-members-table' into leszek/task-985-mem…
magicznyleszek Nov 21, 2024
3847958
Merge branch 'main' into leszek/task-985-member-mutation-api
magicznyleszek Nov 25, 2024
3e9048e
post merge conflict fixes
magicznyleszek Nov 25, 2024
5c8d255
Merge branch 'main' into leszek/task-985-member-mutation-api
magicznyleszek Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion jsapp/js/account/organization/membersQuery.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {keepPreviousData, useQuery} from '@tanstack/react-query';
import {endpoints} from 'js/api.endpoints';
import type {PaginatedResponse} from 'js/dataInterface';
import {fetchGet} from 'js/api';
import {fetchGet, fetchPatch, fetchDelete} from 'js/api';
import {QueryKeys} from 'js/query/queryKeys';
import {useOrganizationQuery, type OrganizationUserRole} from './organizationQuery';

Expand Down Expand Up @@ -34,6 +34,34 @@ export interface OrganizationMember {
};
}

/**
* For updating member within given organization. Accepts partial properties
* of `OrganizationMember`.
*/
export async function patchOrganizationMember(
organizationId: string,
username: string,
newMemberData: Partial<OrganizationMember>
) {
const apiUrl = endpoints.ORGANIZATION_MEMBER_URL
.replace(':organization_id', organizationId)
.replace(':username', username);
return fetchPatch<OrganizationMember>(apiUrl, newMemberData);
}

/**
* For removing member from given organization.
*/
export async function removeOrganizationMember(
organizationId: string,
username: string
) {
const apiUrl = endpoints.ORGANIZATION_MEMBER_URL
.replace(':organization_id', organizationId)
.replace(':username', username);
return fetchDelete(apiUrl);
}

/**
* Fetches paginated list of members for given organization.
* This is mainly needed for `useOrganizationMembersQuery`, so you most probably
Expand Down
4 changes: 4 additions & 0 deletions jsapp/js/account/organization/organizationQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export interface Organization {
request_user_role: OrganizationUserRole;
}

/**
* Note that it's only possible to update the role via API to either `admin` or
* `member`.
*/
export enum OrganizationUserRole {
member = 'member',
admin = 'admin',
Expand Down
1 change: 1 addition & 0 deletions jsapp/js/api.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const endpoints = {
SUBSCRIPTION_URL: '/api/v2/stripe/subscriptions/',
ADD_ONS_URL: '/api/v2/stripe/addons/',
ORGANIZATION_MEMBERS_URL: '/api/v2/organizations/:organization_id/members/',
ORGANIZATION_MEMBER_URL: '/api/v2/organizations/:organization_id/members/:username/',
/** Expected parameters: price_id and organization_id **/
CHECKOUT_URL: '/api/v2/stripe/checkout-link',
/** Expected parameter: organization_id **/
Expand Down