21700: Install Bundler system-wide in Rails postinst
[arvados.git] / services / workbench2 / src / services / link-account-service / link-account-service.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { AxiosInstance } from "axios";
6 import { ApiActions } from "services/api/api-actions";
7 import { AccountToLink, LinkAccountStatus } from "models/link-account";
8 import { CommonService } from "services/common-service/common-service";
9
10 export const USER_LINK_ACCOUNT_KEY = 'accountToLink';
11 export const ACCOUNT_LINK_STATUS_KEY = 'accountLinkStatus';
12
13 export class LinkAccountService {
14
15     constructor(
16         protected serverApi: AxiosInstance,
17         protected actions: ApiActions) { }
18
19     public saveAccountToLink(account: AccountToLink) {
20         sessionStorage.setItem(USER_LINK_ACCOUNT_KEY, JSON.stringify(account));
21     }
22
23     public removeAccountToLink() {
24         sessionStorage.removeItem(USER_LINK_ACCOUNT_KEY);
25     }
26
27     public getAccountToLink() {
28         const data = sessionStorage.getItem(USER_LINK_ACCOUNT_KEY);
29         return data ? JSON.parse(data) as AccountToLink : undefined;
30     }
31
32     public saveLinkOpStatus(status: LinkAccountStatus) {
33         sessionStorage.setItem(ACCOUNT_LINK_STATUS_KEY, JSON.stringify(status));
34     }
35
36     public removeLinkOpStatus() {
37         sessionStorage.removeItem(ACCOUNT_LINK_STATUS_KEY);
38     }
39
40     public getLinkOpStatus() {
41         const data = sessionStorage.getItem(ACCOUNT_LINK_STATUS_KEY);
42         return data ? JSON.parse(data) as LinkAccountStatus : undefined;
43     }
44
45     public linkAccounts(newUserToken: string, newGroupUuid: string) {
46         const params = {
47             new_user_token: newUserToken,
48             new_owner_uuid: newGroupUuid,
49             redirect_to_new_user: true
50         };
51         return CommonService.defaultResponse(
52             this.serverApi.post('/users/merge', params),
53             this.actions,
54             false
55         );
56     }
57 }