2019-11-03 20:20:11 +00:00
|
|
|
import http, { FractalResponseData } from '@/api/http';
|
|
|
|
import { Subuser } from '@/state/server/subusers';
|
|
|
|
|
|
|
|
export const rawDataToServerSubuser = (data: FractalResponseData): Subuser => ({
|
|
|
|
uuid: data.attributes.uuid,
|
|
|
|
username: data.attributes.username,
|
|
|
|
email: data.attributes.email,
|
|
|
|
image: data.attributes.image,
|
|
|
|
twoFactorEnabled: data.attributes['2fa_enabled'],
|
|
|
|
createdAt: new Date(data.attributes.created_at),
|
2020-03-27 21:23:13 +00:00
|
|
|
permissions: data.attributes.permissions || [],
|
|
|
|
can: permission => (data.attributes.permissions || []).indexOf(permission) >= 0,
|
2019-11-03 20:20:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default (uuid: string): Promise<Subuser[]> => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2020-03-27 21:23:13 +00:00
|
|
|
http.get(`/api/client/servers/${uuid}/users`)
|
2019-11-03 20:20:11 +00:00
|
|
|
.then(({ data }) => resolve((data.data || []).map(rawDataToServerSubuser)))
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|