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

[Feature] Transfer project ownership #4743

Merged
merged 162 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
d7e92cd
WIP new button on share page
duvld Nov 29, 2023
afcaba2
WIP django app
noliveleger Nov 9, 2023
b942c12
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
noliveleger Nov 29, 2023
5ea4928
Remove useless print
noliveleger Nov 29, 2023
6ef6680
Get rid of deployment backend identifier
noliveleger Nov 29, 2023
f143937
Updates to transfer section
duvld Nov 30, 2023
78e3303
Merge branch 'feature/transfer-project-ownership' of https://github.c…
duvld Dec 4, 2023
599d63f
WIP modal almost done
duvld Dec 4, 2023
2f4dd77
Transfer project synchronously and submissions asynchronously
noliveleger Nov 30, 2023
ff408f9
Status update mechanism
noliveleger Dec 6, 2023
3359894
Cleaning
noliveleger Dec 6, 2023
a166997
Handle S3 not found file
noliveleger Dec 7, 2023
c8fe296
Refactor status mechanism
noliveleger Dec 8, 2023
a02eddf
Fix mongo rewrite
noliveleger Dec 11, 2023
92f5b6d
Add background tasks
noliveleger Dec 11, 2023
72e8907
Use shadow model to move KC media files
noliveleger Dec 11, 2023
2e6e682
Fix typos for scheduled tasks
noliveleger Dec 11, 2023
b30cbf1
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
noliveleger Dec 11, 2023
c8e8e80
WIP transfer invite modal added
duvld Dec 12, 2023
bbed7a1
Merge branch 'feature/transfer-project-ownership' of https://github.c…
duvld Dec 12, 2023
ffd7f55
Update viewset and serializer
noliveleger Dec 12, 2023
91ceb08
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
noliveleger Dec 12, 2023
dbbde26
Improve viewsets and serializers
noliveleger Dec 13, 2023
004ea19
Rename fields
noliveleger Dec 13, 2023
2955af0
Rename attachments on the file
noliveleger Dec 13, 2023
b7e464f
Fix KC permissions on transfer
noliveleger Dec 13, 2023
630da82
Merge app urls with main appurls - (fix namespace issues)
noliveleger Dec 14, 2023
8b91bbf
Add constance variable to auto accept invites
noliveleger Dec 14, 2023
f0df842
Use constance variable in serializer, fix namespaced reverse calls
noliveleger Dec 14, 2023
42a6490
Merge branch 'beta' into feature/transfer-project-ownership
noliveleger Dec 14, 2023
3550aac
Merge routers
noliveleger Dec 14, 2023
10109f8
Merge branch 'feature/transfer-project-ownership' of https://github.c…
duvld Dec 12, 2023
270fbbd
Merge branch 'feature/transfer-project-ownership' of https://github.c…
duvld Dec 14, 2023
c82ba95
Remove useless try/except
noliveleger Dec 14, 2023
c10d348
Add open_rosa_url to environment endpoint
noliveleger Dec 14, 2023
66d5aa2
Add comment for JS change
noliveleger Dec 14, 2023
71f5d58
Merge branch 'feature/transfer-project-ownership' of https://github.c…
duvld Dec 14, 2023
10579aa
removed check for deployment__identifier in DATA tab
duvld Dec 14, 2023
da319af
Fix crash when submissions as not attachments
noliveleger Dec 14, 2023
4969001
Provide project ownership info in asset serializer
noliveleger Dec 14, 2023
05fb0f5
API doc
noliveleger Dec 15, 2023
87ac176
Make "/transfers" a nested endpoint
noliveleger Dec 15, 2023
fe020ea
Merge branch 'beta' into feature/transfer-project-ownership
noliveleger Dec 15, 2023
3682fd5
Fix asset endpoint error
noliveleger Dec 15, 2023
9faa9cf
Merge branch 'beta' into feature/transfer-project-ownership
noliveleger Dec 15, 2023
7709d91
Optimize relationship querysets
noliveleger Dec 15, 2023
e0660af
WIP hooking up api
Dec 18, 2023
06b353d
Sent in-app messages to users with whom transfer project is shared
noliveleger Dec 18, 2023
fcf6105
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
noliveleger Dec 18, 2023
ae34af7
Allow re-invite after cancellation
noliveleger Dec 18, 2023
4879193
Fix file mispelled
noliveleger Dec 18, 2023
79fd5f2
Send/cancel in sharing page
duvld Dec 18, 2023
d416953
Improve validation error message with bulk transfer
noliveleger Dec 18, 2023
1fd4e80
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
noliveleger Dec 18, 2023
d71063d
Update initial form layout and styling
jamesrkiger Dec 19, 2023
9d4f6b4
Update modal layout
jamesrkiger Dec 19, 2023
d1b1318
Remove function
jamesrkiger Dec 19, 2023
70968c3
*WIP* frontend check for proper invite
Dec 19, 2023
906528e
*WIP* invite checking fixes
Dec 19, 2023
9c8ca8a
Invite expire, new mailer utility
noliveleger Dec 19, 2023
3dd0b3c
Avoid sending empty emails
noliveleger Dec 19, 2023
fbd8129
Send emails: new, declined, expired
noliveleger Dec 19, 2023
2cf77b7
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
noliveleger Dec 19, 2023
5fc74dd
do not send in-app messages to old and new owner
noliveleger Dec 19, 2023
ce094c5
Allow expired invite to be resent
noliveleger Dec 19, 2023
5c0ba62
Email: Add Accepted invite, fix text typos
noliveleger Dec 19, 2023
0e218a9
Add forgotten templates
noliveleger Dec 19, 2023
415d5aa
Handle single project transfer in templates
noliveleger Dec 19, 2023
8d0e2f5
Add invitation acceptance modal styling
jamesrkiger Dec 20, 2023
4eea34f
Fix header color
jamesrkiger Dec 20, 2023
f292f6a
Merge branch 'feature/transfer-project-ownership' into transfer-proje…
jamesrkiger Dec 20, 2023
2d1238e
Merge branch 'beta' into feature/transfer-project-ownership
noliveleger Dec 20, 2023
2ab55c8
Fix wrong default value with constance
noliveleger Dec 20, 2023
1f2e087
Handle bad requests, improve username input ui
jamesrkiger Dec 20, 2023
54f072d
Send failure reports to admin
noliveleger Dec 20, 2023
2ffcfac
Unit tests skeleton
noliveleger Dec 20, 2023
1ec7e41
Fix unit tests with api v2 namespace
noliveleger Dec 20, 2023
16f48ae
APi v2 structure
noliveleger Dec 21, 2023
f2c0154
Merge branch 'require-auth-at-project-level' into feature/transfer-pr…
noliveleger Dec 21, 2023
af28b99
Fix merge conflict
noliveleger Dec 21, 2023
6d8e32e
Merge branch 'feature/transfer-project-ownership' into transfer-proje…
duvld Dec 21, 2023
e7a9d4d
Merge pull request #4773 from kobotoolbox/transfer-project-ownership-…
duvld Dec 21, 2023
a3f3af9
Fix 500 on create invite
noliveleger Dec 21, 2023
e0c39d0
Review periodic tasks
noliveleger Dec 21, 2023
2f48dc7
Add missing documentation
noliveleger Dec 21, 2023
4b2f35e
Draft - Unit tests
noliveleger Dec 21, 2023
a8c0557
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
noliveleger Dec 21, 2023
c379675
Fix bad copy/paste in API doc
noliveleger Dec 21, 2023
aaa1db1
Update unit tests
noliveleger Dec 21, 2023
1ebcad4
Accepting/Declining invite and WIP {name} replace
duvld Dec 21, 2023
c81feed
Add sender and asset__name to API response
noliveleger Dec 21, 2023
086403d
Merge branch 'feature/transfer-project-ownership' of https://github.c…
duvld Dec 21, 2023
c8d32c5
Bugfixes
noliveleger Dec 21, 2023
805b33e
Python 3.8 annotations bugfix
noliveleger Dec 21, 2023
3e1f7b2
Update unit tests
noliveleger Dec 22, 2023
59cce48
Add FIXME, and fix typos
noliveleger Dec 22, 2023
d96a473
Invite expiry threshold fix
noliveleger Dec 23, 2023
222a71b
Merge branch 'feature/transfer-project-ownership' into catch-invalid-…
jamesrkiger Dec 26, 2023
3a59567
Show pending ownership for users with existing permissions
jamesrkiger Dec 26, 2023
40d2f3d
Add row for users without permissions
jamesrkiger Dec 26, 2023
56b28ad
String interpolation for project and invite recipient names.
jamesrkiger Dec 26, 2023
ce5474f
Merge pull request #4777 from kobotoolbox/catch-invalid-username
duvld Dec 26, 2023
3bf93e6
Added some error handling, needs to be cleaned up
Dec 26, 2023
721ae97
Use permissions row component
jamesrkiger Dec 27, 2023
a8803e3
Merge pull request #4785 from kobotoolbox/show-perms-row-pending-owne…
duvld Dec 27, 2023
c73e801
Add unit tests, some broken
jamesrkiger Dec 27, 2023
ad5f43d
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
jamesrkiger Dec 27, 2023
782146c
Skip broken tests
jamesrkiger Dec 27, 2023
4db27b9
Fix in-app-messages being sent to everyone
jamesrkiger Dec 28, 2023
158e277
Added banners for accepting/declining invites
Dec 28, 2023
82eab70
Merge branch 'feature/transfer-project-ownership' of https://github.c…
Dec 28, 2023
c62d641
Add some working email tests
jamesrkiger Dec 28, 2023
d90d915
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
jamesrkiger Dec 28, 2023
cb60d4b
Fix test/email recipient
jamesrkiger Dec 28, 2023
c08fa65
Finish email tests
jamesrkiger Dec 28, 2023
28e3b5b
Frontend check for self transfer, improves warning
Dec 28, 2023
c0a5e42
Disable FF autocomplete
jamesrkiger Jan 2, 2024
e61dcf8
Linting
jamesrkiger Jan 2, 2024
d150e37
Same as 8a945e. Fixed unabled to remove all perms
Jan 9, 2024
9d54ec8
Link 'Learn more' to sharing permissions article
Jan 9, 2024
f766e69
Fix scoping of anonymousSubmission CSS
Jan 11, 2024
bda7a8d
Linting - 80 chars max
noliveleger Jan 11, 2024
e6a8e8f
Cancel invites on asset deletion
noliveleger Jan 11, 2024
ac6215e
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
noliveleger Jan 11, 2024
6420f3a
WIP test service usage on transfer
noliveleger Jan 11, 2024
62f0dd6
Merge branch 'require-auth-at-project-level' into feature/transfer-pr…
noliveleger Jan 11, 2024
2d90a7c
Use django_redis instead of redis client
noliveleger Jan 11, 2024
b33198b
Merge branch 'beta' into feature/transfer-project-ownership
noliveleger Jan 11, 2024
b26b3a1
Fix bad merge
noliveleger Jan 11, 2024
5526981
Remove search params on accept/decline invite and add loading state
jamesrkiger Jan 15, 2024
f90534f
Add unit tests for data transfer
noliveleger Jan 16, 2024
6188be9
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
noliveleger Jan 16, 2024
33b36d4
Add unit test for ExtendedFileField.move() method
noliveleger Jan 16, 2024
05ee69a
Merge branch 'beta' into feature/transfer-project-ownership
noliveleger Jan 16, 2024
acf23f2
Fix bad merge
noliveleger Jan 16, 2024
c0c2dc8
Delete temporary files in ExtendedFileField.move() unit test
noliveleger Jan 16, 2024
ddd6482
Fix move file with local storage
noliveleger Jan 16, 2024
6fee370
Move soft deleted attachments as well
noliveleger Jan 16, 2024
fc749ce
Merge branch 'release/2.024.04' into feature/transfer-project-ownership
noliveleger Jan 24, 2024
d164d3f
Do not use kobocat ref in basedeploymentbackend
noliveleger Jan 24, 2024
97fa9ad
Fix unit tests after merge conflicts
noliveleger Jan 24, 2024
2d4b092
Fix duplicate CSS from merge
duvld Jan 24, 2024
ed74342
Merge branch 'feature/transfer-project-ownership' of https://github.c…
duvld Jan 24, 2024
470c452
Fix forgotten property decorator
noliveleger Jan 25, 2024
4bac4cf
Merge branch 'release/2.024.05' into feature/transfer-project-ownership
noliveleger Feb 12, 2024
224b158
Merge branch 'release/2.024.05' into feature/transfer-project-ownership
noliveleger Feb 19, 2024
c02e6bd
Remove "- KoboToolbox" from in-app message
noliveleger Feb 19, 2024
c552481
Merge branch 'release/2.024.07' into feature/transfer-project-ownership
noliveleger Feb 19, 2024
4697bd8
Merge branch 'release/2.024.07' into feature/transfer-project-ownership
noliveleger Feb 22, 2024
ff0c698
Most PR changes. TODO: better translation strings
duvld Feb 27, 2024
b397e5f
Merge branch 'feature/transfer-project-ownership' of https://github.c…
duvld Feb 27, 2024
b42b862
Merge branch 'release/2.024.07' into feature/transfer-project-ownership
noliveleger Feb 27, 2024
00b28ee
Merge branch 'feature/transfer-project-ownership' of github.com:kobot…
noliveleger Feb 27, 2024
f021dcd
Move test_question_xpaths logic to API unit test
noliveleger Feb 27, 2024
c7bd54f
Merge branch 'refactor-counter-shadow-models' into feature/transfer-p…
noliveleger Feb 28, 2024
0637f2c
Merge branch 'refactor-api-v2-urls' into feature/transfer-project-own…
noliveleger Feb 28, 2024
e3ed7ff
Merge branch 'lint-format-pre-transfer-project-ownership' into featur…
noliveleger Feb 28, 2024
4ca0037
Pr changes: translation string & organizing files
duvld Mar 4, 2024
582806d
Add missing refactored folder, new comment for inv
duvld Mar 4, 2024
76d21ef
Merge branch 'release/2.024.09' into feature/transfer-project-ownership
duvld Mar 11, 2024
9e239d7
Apply requested changes for PR#4743
noliveleger Mar 14, 2024
834ec51
Fix draft project transfers
noliveleger Mar 19, 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
4 changes: 4 additions & 0 deletions jsapp/js/components/common/icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ $s-icon-xl: 28px;
color: colors.$kobo-red;
}

.k-icon.k-icon--color-blue {
color: colors.$kobo-blue;
}

.k-icon.k-icon--color-amber {
color: colors.$kobo-amber;
}
2 changes: 1 addition & 1 deletion jsapp/js/components/common/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import './icon.scss';
* Check out `icon.scss` file for exact pixel values.
*/
export type IconSize = 'l' | 'm' | 's' | 'xl' | 'xs' | 'xxs';
export type IconColor = 'red' | 'storm' | 'teal' | 'amber';
export type IconColor = 'red' | 'storm' | 'teal' | 'amber' | 'blue';

const DefaultSize = 's';

Expand Down
6 changes: 6 additions & 0 deletions jsapp/js/components/formLanding.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ class FormLanding extends React.Component {
kc_server.href = this.state.deployment__identifier;
var kobocollect_url = kc_server.origin;

/* TODO
`deployment__identifier` has been removed from API response.
Stop reading `kc_server` from `deployment__identifier` and use `open_rosa_server`
property provided in `/environment` endpoint
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create Notion task for this?


return (
<bem.FormView__row>
<bem.FormView__cell m={['label', 'first']}>
Expand Down
5 changes: 5 additions & 0 deletions jsapp/js/components/formSubScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import RESTServices from './RESTServices';
import LoadingSpinner from 'js/components/common/loadingSpinner';
import {ROUTES} from 'js/router/routerConstants';
import {withRouter} from 'js/router/legacy';
import sessionStore from 'js/stores/session';
import TransferProjects from 'js/components/permissions/transferProjects/transferProjects.component';

const ConnectProjects = React.lazy(() =>
import(
Expand Down Expand Up @@ -137,9 +139,12 @@ export class FormSubScreens extends React.Component {
}
renderSharing() {
const uid = this.props.params.assetid || this.props.params.uid;

return (
<bem.FormView m='form-settings-sharing'>
<SharingForm assetUid={uid} />

<TransferProjects asset={this.state} />
</bem.FormView>
);
}
Expand Down
7 changes: 5 additions & 2 deletions jsapp/js/components/modals/koboModal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ $kobo-modal-header-icon-margin: sizes.$x10;
padding: $kobo-modal-padding;
border-radius: sizes.$x6 sizes.$x6 0 0;

&.kobo-modal__header--red{
&.kobo-modal__header--red {
background-color: color.change(colors.$kobo-red, $alpha: 0.1);
}
&.kobo-modal__header--grey{
&.kobo-modal__header--grey {
background-color: colors.$kobo-gray-98;
}
&.kobo-modal__header--white {
background-color: colors.$kobo-white;
}

h1 {
@include mixins.centerRowFlex;
Expand Down
2 changes: 1 addition & 1 deletion jsapp/js/components/modals/koboModalHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bem.KoboModal__header = makeBem(bem.KoboModal, 'header', 'header');
bem.KoboModal__headerIcon = makeBem(bem.KoboModal, 'header-icon', 'span');

export type KoboModalHeaderIconColors = 'blue' | 'red' | 'storm';
export type KoboModalHeaderBackgroundColors = 'red' | 'grey';
export type KoboModalHeaderBackgroundColors = 'red' | 'grey' | 'white';

interface KoboModalHeaderProps {
/** Optional icon displayed on the left of the title. */
Expand Down
38 changes: 38 additions & 0 deletions jsapp/js/components/permissions/sharingForm.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {replaceBracketsWithLink} from 'js/textUtils';
import {ANON_USERNAME, ANON_USERNAME_URL} from 'js/users/utils';
import {ASSET_TYPES} from 'js/constants';
import {ACCOUNT_ROUTES} from 'js/account/routes';
import {TransferStatuses} from 'js/components/permissions/transferProjects/transferProjects.api';
import './sharingForm.scss';
// parts
import CopyTeamPermissions from './copyTeamPermissions.component';
Expand Down Expand Up @@ -162,6 +163,41 @@ export default class SharingForm extends React.Component<
}
}

/** Check if the recipient of the transfer is the specified user */
isPendingOwner(username: string) {
duvld marked this conversation as resolved.
Show resolved Hide resolved
return this.state.asset?.project_ownership?.status ===
TransferStatuses.Pending &&
this.state.asset?.project_ownership?.recipient === username
? true
: false;
}

/** Display pending owner if not already included in list of user permissions */
renderPendingOwner() {
if (
this.state.asset?.project_ownership?.status ===
TransferStatuses.Pending &&
!this.state.permissions?.find(
(perm) =>
perm.user.name === this.state.asset?.project_ownership?.recipient
)
) {
return (
<UserPermissionRow
assetUid={this.props.assetUid}
nonOwnerPerms={this.state.nonOwnerPerms}
assignablePerms={this.state.assignablePerms}
permissions={[]}
isUserOwner={false}
isPendingOwner={true}
username={this.state.asset.project_ownership.recipient}
/>
);
} else {
return null;
}
}

render() {
if (!this.state.asset || !this.state.permissions) {
return <LoadingSpinner />;
Expand Down Expand Up @@ -217,10 +253,12 @@ export default class SharingForm extends React.Component<
assignablePerms={this.state.assignablePerms}
permissions={perm.permissions}
isUserOwner={perm.user.isOwner}
isPendingOwner={this.isPendingOwner(perm.user.name)}
username={perm.user.name}
/>
);
})}
{this.renderPendingOwner()}

{!this.state.isAddUserEditorVisible && (
<Button
Expand Down
2 changes: 0 additions & 2 deletions jsapp/js/components/permissions/sharingForm.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ $s-gray-row-spacing: 10px;
}

.copy-team-permissions {
margin-bottom: 30px;

&.copy-team-permissions--opened
.copy-team-permissions-opener
.k-icon::before {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import {FailResponse, PaginatedResponse} from 'js/dataInterface';
import {fetchGet, fetchPost, fetchPatch} from 'jsapp/js/api';
import sessionStore from 'js/stores/session';
import {buildUserUrl, getUsernameFromUrl} from 'js/users/utils';
import {notify} from 'js/utils';
import {handleApiFail} from 'js/api';

const INVITE_URL = '/api/v2/project-ownership/invites/';

/**
* The status of a project transfer.
*/
export enum TransferStatuses {
/**Sender sent the invite but recipient hasn't responded yet.*/
Pending = 'pending',
/**Sender sent the invite but cancelled it before the recipient could respond.*/
Cancelled = 'cancelled',
/**Recipient has declined the invite.*/
Declined = 'declined',
/**Recipient has accepted the invite but transfer process has not started yet*/
Accepted = 'accepted',
/**Recipient has accepted and the transfer process has begun.*/
InProgress = 'in_progress',
/**Recipient has accepted and transfer has completed successfully.*/
Complete = 'complete',
/**Recipient has accepted and process went south.*/
Failed = 'failed',
}

/**Detail about a single asset's transfer. This is listed in the invite detail.*/
export interface ProjectTransfer {
url: string;
asset: string;
asset__name: string;
status: TransferStatuses;
error: any;
date_modified: string;
}

/**Detail about current asset's transfer. This is listed in the asset detail.*/
export interface ProjectTransferAssetDetail {
invite: string;
sender: string;
recipient: string;
status: TransferStatuses;
}

export interface InvitesResponse {
url: string;
sender: string;
recipient: string;
status: TransferStatuses;
date_created: string;
date_modified: string;
/**
* Backend is written such that invites can have multiple
* projects per transfer. This is not supported by the UI right now.
*/
transfers: ProjectTransfer[];
}

export async function sendInvite(username: string, assetUid: string) {
return fetchPost<InvitesResponse>(INVITE_URL, {
recipient: buildUserUrl(username),
assets: [assetUid],
});
}

// Note: the following invite actions are seperated to make it clearer when using in
// the JSX code.

export async function cancelInvite(inviteUrl: string) {
let response;
try {
response = await fetchPatch<InvitesResponse>(
inviteUrl,
{
status: TransferStatuses.Cancelled,
},
{prependRootUrl: false, notifyAboutError: false}
);
} catch (error) {
handleApiFail(
error as FailResponse,
t(
'Failed to cancel transfer. The transfer may be declined or accpeted already. Please check your email.'
)
);
}

return response;
}

export async function acceptInvite(inviteUid: string) {
let response;
try {
response = await fetchPatch<InvitesResponse>(
INVITE_URL + inviteUid + '/',
{
status: TransferStatuses.Accepted,
},
{prependRootUrl: false, notifyAboutError: false}
);
} catch (error) {
handleApiFail(
error as FailResponse,
t(
'Failed to accept invite.'
)
);
}

return response;
}

export async function declineInvite(inviteUid: string) {
let response;
try {
response = await fetchPatch<InvitesResponse>(
INVITE_URL + inviteUid + '/',
{
status: TransferStatuses.Declined,
},
{prependRootUrl: false, notifyAboutError: false}
);
} catch (error) {
handleApiFail(
error as FailResponse,
t(
'Failed to decline invite'
)
);
}
return response;
}

/**Returns *all invites* the current user sent or recieved.*/
export async function getAllInvites() {
let invites;
try {
invites = await fetchGet<PaginatedResponse<InvitesResponse>>(INVITE_URL, {notifyAboutError: false});
} catch (error) {
handleApiFail(
error as FailResponse,
);
}

return invites;
}

/**
* Returns detail for a single invite.
*
* Note: backend is written such that invites can have multiple
* projects per transfer. This is not supported by the UI right now.
*/
export async function getInviteDetail(inviteUid: string) {
return fetchGet<InvitesResponse>(INVITE_URL + inviteUid, {notifyAboutError: false});
}

/** Check if the invite is meant for the currently logged in user. */
export async function isInviteForLoggedInUser(inviteUid: string) {
let inviteIsCorrect = false;
try {
await getInviteDetail(inviteUid).then((data) => {
// Only bother with the check if it's in the `pending` state.
if (data.status !== TransferStatuses.Pending) {
notify.warning(t('Invite has been cancelled or expired'));
return;
}

inviteIsCorrect =
sessionStore.currentAccount.username ===
getUsernameFromUrl(data.recipient);
});
} catch (error) {
handleApiFail(
error as FailResponse,
t(
'Invite is invaild.'
)
);
}

return inviteIsCorrect;
}

export async function getAssetFromInviteUid(inviteUid: string) {
let displayDetails = null;
try {
await getInviteDetail(inviteUid).then((data) => {
displayDetails = {
assetName: data.transfers[0].asset__name,
assetOwner: getUsernameFromUrl(data.sender),
};
});
} catch (error) {
handleApiFail(
error as FailResponse,
);
}
return displayDetails;
}
Loading
Loading