2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* This module exports a UserManager component, consisting of a list of emails, each with an
|
|
|
|
* associated role (See app/common/roles), and a way to change roles, and add or remove new users.
|
|
|
|
* The component is instantiated as a modal with a confirm button to pass changes to the server.
|
|
|
|
*
|
|
|
|
* It can be instantiated by calling showUserManagerModal with the UserAPI and IUserManagerOptions.
|
|
|
|
*/
|
2021-10-25 16:54:04 +00:00
|
|
|
import {commonUrls} from 'app/common/gristUrls';
|
2022-10-05 14:19:28 +00:00
|
|
|
import {capitalizeFirstWord, isLongerThan} from 'app/common/gutil';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {FullUser} from 'app/common/LoginSessionAPI';
|
|
|
|
import * as roles from 'app/common/roles';
|
2021-11-05 14:47:17 +00:00
|
|
|
import {Organization, PermissionData, UserAPI} from 'app/common/UserAPI';
|
2022-11-28 14:02:32 +00:00
|
|
|
import {Computed, Disposable, dom, DomElementArg, Observable, observable, styled} from 'grainjs';
|
2021-10-25 16:54:04 +00:00
|
|
|
import pick = require('lodash/pick');
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2022-09-21 14:30:54 +00:00
|
|
|
import {ACIndexImpl, normalizeText} from 'app/client/lib/ACIndex';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {copyToClipboard} from 'app/client/lib/copyToClipboard';
|
|
|
|
import {setTestState} from 'app/client/lib/testState';
|
2022-11-28 14:02:32 +00:00
|
|
|
import {buildMultiUserManagerModal} from 'app/client/lib/MultiUserManager';
|
2022-09-21 14:30:54 +00:00
|
|
|
import {ACUserItem, buildACMemberEmail} from 'app/client/lib/ACUserManager';
|
2021-10-25 16:54:04 +00:00
|
|
|
import {AppModel} from 'app/client/models/AppModel';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {DocPageModel} from 'app/client/models/DocPageModel';
|
|
|
|
import {reportError} from 'app/client/models/errors';
|
2020-11-26 02:29:13 +00:00
|
|
|
import {urlState} from 'app/client/models/gristUrlState';
|
2021-11-05 14:47:17 +00:00
|
|
|
import {IEditableMember, IMemberSelectOption, IOrgMemberSelectOption,
|
|
|
|
Resource} from 'app/client/models/UserManagerModel';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {UserManagerModel, UserManagerModelImpl} from 'app/client/models/UserManagerModel';
|
|
|
|
import {getResourceParent, ResourceType} from 'app/client/models/UserManagerModel';
|
2022-10-19 23:06:05 +00:00
|
|
|
import {GristTooltips} from 'app/client/ui/GristTooltips';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {shadowScroll} from 'app/client/ui/shadowScroll';
|
2022-10-19 23:06:05 +00:00
|
|
|
import {hoverTooltip, ITooltipControl, showTransientTooltip, withInfoTooltip} from 'app/client/ui/tooltips';
|
2022-09-21 14:30:54 +00:00
|
|
|
import {createUserImage} from 'app/client/ui/UserImage';
|
|
|
|
import {cssMemberBtn, cssMemberImage, cssMemberListItem,
|
2021-10-25 16:54:04 +00:00
|
|
|
cssMemberPrimary, cssMemberSecondary, cssMemberText, cssMemberType, cssMemberTypeProblem,
|
|
|
|
cssRemoveIcon} from 'app/client/ui/UserItem';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {basicButton, bigBasicButton, bigPrimaryButton} from 'app/client/ui2018/buttons';
|
2022-09-21 14:30:54 +00:00
|
|
|
import {mediaXSmall, testId, theme, vars} from 'app/client/ui2018/cssVars';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
2020-12-04 23:29:29 +00:00
|
|
|
import {cssLink} from 'app/client/ui2018/links';
|
2022-05-19 04:51:48 +00:00
|
|
|
import {loadingSpinner} from 'app/client/ui2018/loaders';
|
2022-09-21 14:30:54 +00:00
|
|
|
import {menu, menuItem, menuText} from 'app/client/ui2018/menus';
|
2022-12-27 18:35:03 +00:00
|
|
|
import {confirmModal, cssAnimatedModal, cssModalBody, cssModalButtons, cssModalTitle,
|
|
|
|
IModalControl, modal} from 'app/client/ui2018/modals';
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
export interface IUserManagerOptions {
|
|
|
|
permissionData: Promise<PermissionData>;
|
2022-05-19 04:51:48 +00:00
|
|
|
activeUser: FullUser|null;
|
2020-10-02 15:10:00 +00:00
|
|
|
resourceType: ResourceType;
|
|
|
|
resourceId: string|number;
|
2021-11-05 14:47:17 +00:00
|
|
|
resource?: Resource;
|
2020-10-02 15:10:00 +00:00
|
|
|
docPageModel?: DocPageModel;
|
2021-10-25 16:54:04 +00:00
|
|
|
appModel?: AppModel; // If present, we offer access to a nested team-level dialog.
|
2020-11-26 02:29:13 +00:00
|
|
|
linkToCopy?: string;
|
2021-10-25 16:54:04 +00:00
|
|
|
reload?: () => Promise<PermissionData>;
|
2022-04-12 19:31:41 +00:00
|
|
|
onSave?: (personal: boolean) => Promise<unknown>;
|
2021-10-25 16:54:04 +00:00
|
|
|
prompt?: { // If set, user manager should open with this email filled in and ready to go.
|
|
|
|
email: string;
|
|
|
|
};
|
2021-11-05 14:47:17 +00:00
|
|
|
showAnimation?: boolean; // If true, animates opening of the modal. Defaults to false.
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns an instance of UserManagerModel given IUserManagerOptions. Makes the async call for the
|
|
|
|
// required properties of the options.
|
|
|
|
async function getModel(options: IUserManagerOptions): Promise<UserManagerModelImpl> {
|
|
|
|
const permissionData = await options.permissionData;
|
2022-05-19 04:51:48 +00:00
|
|
|
return new UserManagerModelImpl(
|
|
|
|
permissionData, options.resourceType,
|
|
|
|
pick(options, ['activeUser', 'reload', 'appModel', 'docPageModel', 'resource'])
|
|
|
|
);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public interface for creating the UserManager in the app. Creates a modal that includes
|
|
|
|
* the UserManager menu with save and cancel buttons.
|
|
|
|
*/
|
|
|
|
export function showUserManagerModal(userApi: UserAPI, options: IUserManagerOptions) {
|
2022-06-03 14:58:07 +00:00
|
|
|
const modelObs: Observable<UserManagerModel|null|"slow"> = observable(null);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2020-12-04 23:29:29 +00:00
|
|
|
async function onConfirm(ctl: IModalControl) {
|
|
|
|
const model = modelObs.get();
|
2022-06-03 14:58:07 +00:00
|
|
|
if (!model || model === "slow") {
|
2022-04-12 19:31:41 +00:00
|
|
|
ctl.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const tryToSaveChanges = async () => {
|
2020-12-04 23:29:29 +00:00
|
|
|
// Save changes to the server, reporting any errors to the app.
|
|
|
|
try {
|
2022-04-12 19:31:41 +00:00
|
|
|
const isAnythingChanged = model.isAnythingChanged.get();
|
|
|
|
if (isAnythingChanged) {
|
2020-12-04 23:29:29 +00:00
|
|
|
await model.save(userApi, options.resourceId);
|
|
|
|
}
|
2022-04-12 19:31:41 +00:00
|
|
|
await options.onSave?.(model.isPersonal);
|
2020-12-04 23:29:29 +00:00
|
|
|
ctl.close();
|
2022-04-12 19:31:41 +00:00
|
|
|
if (model.isPersonal && isAnythingChanged) {
|
|
|
|
// the only thing an individual without ACL_EDIT rights can do is
|
|
|
|
// remove themselves - so reload.
|
|
|
|
window.location.reload();
|
|
|
|
}
|
2020-12-04 23:29:29 +00:00
|
|
|
} catch (err) {
|
|
|
|
reportError(err);
|
|
|
|
}
|
2022-04-12 19:31:41 +00:00
|
|
|
};
|
|
|
|
if (model.isSelfRemoved.get()) {
|
|
|
|
const name = resourceName(model.resourceType);
|
|
|
|
confirmModal(
|
|
|
|
`You are about to remove your own access to this ${name}`,
|
|
|
|
'Remove my access', tryToSaveChanges,
|
2023-04-20 13:07:45 +00:00
|
|
|
{
|
|
|
|
explanation: (
|
|
|
|
'Once you have removed your own access, ' +
|
|
|
|
'you will not be able to get it back without assistance ' +
|
|
|
|
`from someone else with sufficient access to the ${name}.`
|
|
|
|
),
|
|
|
|
}
|
|
|
|
);
|
2020-12-04 23:29:29 +00:00
|
|
|
} else {
|
2022-04-12 19:31:41 +00:00
|
|
|
tryToSaveChanges().catch(reportError);
|
2020-12-04 23:29:29 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Get the model and assign it to the observable. Report errors to the app.
|
2022-06-03 14:58:07 +00:00
|
|
|
const waitPromise = getModel(options)
|
2020-10-02 15:10:00 +00:00
|
|
|
.then(model => modelObs.set(model))
|
|
|
|
.catch(reportError);
|
2022-05-19 04:51:48 +00:00
|
|
|
|
2022-06-03 14:58:07 +00:00
|
|
|
isLongerThan(waitPromise, 400).then((slow) => slow && modelObs.set("slow")).catch(() => {});
|
|
|
|
|
2022-05-19 04:51:48 +00:00
|
|
|
return buildUserManagerModal(modelObs, onConfirm, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildUserManagerModal(
|
2022-06-03 14:58:07 +00:00
|
|
|
modelObs: Observable<UserManagerModel|null|"slow">,
|
2022-05-19 04:51:48 +00:00
|
|
|
onConfirm: (ctl: IModalControl) => Promise<void>,
|
|
|
|
options: IUserManagerOptions
|
|
|
|
) {
|
|
|
|
return modal(ctl => [
|
2020-10-02 15:10:00 +00:00
|
|
|
// We set the padding to 0 since the body scroll shadows extend to the edge of the modal.
|
|
|
|
{ style: 'padding: 0;' },
|
2021-11-05 14:47:17 +00:00
|
|
|
options.showAnimation ? dom.cls(cssAnimatedModal.className) : null,
|
2022-05-19 04:51:48 +00:00
|
|
|
dom.domComputed(modelObs, model => {
|
2022-06-03 14:58:07 +00:00
|
|
|
if (!model) { return null; }
|
|
|
|
if (model === "slow") { return cssSpinner(loadingSpinner()); }
|
2022-05-19 04:51:48 +00:00
|
|
|
|
|
|
|
const cssBody = model.isPersonal ? cssAccessDetailsBody : cssUserManagerBody;
|
|
|
|
return [
|
2022-06-03 14:58:07 +00:00
|
|
|
cssTitle(
|
|
|
|
renderTitle(options.resourceType, options.resource, model.isPersonal),
|
|
|
|
(options.resourceType === 'document' && (!model.isPersonal || model.isPublicMember)
|
|
|
|
? makeCopyBtn(options.linkToCopy, cssCopyBtn.cls('-header'))
|
|
|
|
: null
|
|
|
|
),
|
|
|
|
testId('um-header'),
|
|
|
|
),
|
2022-05-19 04:51:48 +00:00
|
|
|
cssModalBody(
|
|
|
|
cssBody(
|
|
|
|
new UserManager(
|
2022-11-28 14:02:32 +00:00
|
|
|
model,
|
|
|
|
pick(options, 'linkToCopy', 'docPageModel', 'appModel', 'prompt', 'resource')
|
2022-05-19 04:51:48 +00:00
|
|
|
).buildDom()
|
|
|
|
),
|
|
|
|
),
|
|
|
|
cssModalButtons(
|
|
|
|
{ style: 'margin: 32px 64px; display: flex;' },
|
|
|
|
(model.isPublicMember ? null :
|
|
|
|
bigPrimaryButton('Confirm',
|
|
|
|
dom.boolAttr('disabled', (use) => !use(model.isAnythingChanged)),
|
|
|
|
dom.on('click', () => onConfirm(ctl)),
|
|
|
|
testId('um-confirm')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
bigBasicButton(
|
|
|
|
model.isPublicMember ? 'Close' : 'Cancel',
|
|
|
|
dom.on('click', () => ctl.close()),
|
|
|
|
testId('um-cancel')
|
|
|
|
),
|
|
|
|
(model.resourceType === 'document' && model.gristDoc && !model.isPersonal
|
2022-10-19 23:06:05 +00:00
|
|
|
? withInfoTooltip(
|
|
|
|
cssLink({href: urlState().makeUrl({docPage: 'acl'})},
|
|
|
|
dom.text(use => use(model.isAnythingChanged) ? 'Save & ' : ''),
|
|
|
|
'Open Access Rules',
|
|
|
|
dom.on('click', (ev) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
return onConfirm(ctl).then(() => urlState().pushUrl({docPage: 'acl'}));
|
|
|
|
}),
|
|
|
|
testId('um-open-access-rules'),
|
|
|
|
),
|
|
|
|
GristTooltips.openAccessRules(),
|
|
|
|
{domArgs: [cssAccessLink.cls('')]},
|
2022-05-19 04:51:48 +00:00
|
|
|
)
|
|
|
|
: null
|
|
|
|
),
|
|
|
|
testId('um-buttons'),
|
2021-11-17 00:17:21 +00:00
|
|
|
)
|
2022-05-19 04:51:48 +00:00
|
|
|
];
|
|
|
|
})
|
2020-10-02 15:10:00 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See module documentation for overview.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* const um = new UserManager(model);
|
|
|
|
* um.buildDom();
|
|
|
|
*/
|
|
|
|
export class UserManager extends Disposable {
|
2021-10-25 16:54:04 +00:00
|
|
|
private _dom: HTMLDivElement;
|
2022-11-28 14:02:32 +00:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private _model: UserManagerModel,
|
|
|
|
private _options: {
|
|
|
|
linkToCopy?: string,
|
|
|
|
docPageModel?: DocPageModel,
|
|
|
|
appModel?: AppModel,
|
|
|
|
prompt?: {email: string},
|
|
|
|
resource?: Resource,
|
2021-10-25 16:54:04 +00:00
|
|
|
}) {
|
2020-10-02 15:10:00 +00:00
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public buildDom() {
|
2022-05-19 04:51:48 +00:00
|
|
|
if (this._model.isPublicMember) {
|
|
|
|
return this._buildSelfPublicAccessDom();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._model.isPersonal) {
|
|
|
|
return this._buildSelfAccessDom();
|
|
|
|
}
|
|
|
|
|
2022-11-28 14:02:32 +00:00
|
|
|
const acMemberEmail = this.autoDispose(new ACMemberEmail(
|
|
|
|
this._onAdd.bind(this),
|
|
|
|
this._model.membersEdited.get(),
|
|
|
|
this._options.prompt,
|
|
|
|
));
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
return [
|
2022-09-27 21:06:02 +00:00
|
|
|
acMemberEmail.buildDom(),
|
2022-05-19 04:51:48 +00:00
|
|
|
this._buildOptionsDom(),
|
2021-10-25 16:54:04 +00:00
|
|
|
this._dom = shadowScroll(
|
2020-10-02 15:10:00 +00:00
|
|
|
testId('um-members'),
|
|
|
|
this._buildPublicAccessMember(),
|
|
|
|
dom.forEach(this._model.membersEdited, (member) => this._buildMemberDom(member)),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-11-28 14:02:32 +00:00
|
|
|
private _onAddOrEdit(email: string, role: roles.NonGuestRole) {
|
|
|
|
const members = this._model.membersEdited.get();
|
|
|
|
const maybeMember = members.find(m => m.email === email);
|
|
|
|
if (maybeMember) {
|
|
|
|
maybeMember.access.set(role);
|
|
|
|
} else {
|
|
|
|
this._onAdd(email, role);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-25 16:54:04 +00:00
|
|
|
private _onAdd(email: string, role: roles.NonGuestRole) {
|
|
|
|
this._model.add(email, role);
|
|
|
|
// Make sure the entry we have just added is actually visible - confusing if not.
|
|
|
|
Array.from(this._dom.querySelectorAll('.member-email'))
|
|
|
|
.find(el => el.textContent === email)
|
|
|
|
?.scrollIntoView();
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
private _buildOptionsDom(): Element {
|
|
|
|
const publicMember = this._model.publicMember;
|
2022-10-19 23:06:05 +00:00
|
|
|
let tooltipControl: ITooltipControl | undefined;
|
2022-11-28 14:02:32 +00:00
|
|
|
return dom('div',
|
|
|
|
cssOptionRowMultiple(
|
|
|
|
icon('AddUser'),
|
|
|
|
cssLabel('Invite multiple'),
|
|
|
|
dom.on('click', (_ev) => buildMultiUserManagerModal(
|
|
|
|
this,
|
|
|
|
this._model,
|
|
|
|
(email, role) => {
|
|
|
|
this._onAddOrEdit(email, role);
|
|
|
|
},
|
|
|
|
))
|
2020-10-02 15:10:00 +00:00
|
|
|
),
|
2022-11-28 14:02:32 +00:00
|
|
|
cssOptionRow(
|
|
|
|
// TODO: Consider adding a tooltip explaining inheritance. A brief text caption may
|
|
|
|
// be used to fill whitespace in org UserManager.
|
|
|
|
this._model.isOrg ? null : dom('span', { style: `float: left;` },
|
|
|
|
dom('span', 'Inherit access: '),
|
|
|
|
this._inheritRoleSelector()
|
2022-10-19 23:06:05 +00:00
|
|
|
),
|
2022-11-28 14:02:32 +00:00
|
|
|
publicMember ? dom('span', { style: `float: right;` },
|
|
|
|
cssSmallPublicMemberIcon('PublicFilled'),
|
|
|
|
dom('span', 'Public access: '),
|
|
|
|
cssOptionBtn(
|
|
|
|
menu(() => {
|
|
|
|
tooltipControl?.close();
|
|
|
|
return [
|
|
|
|
menuItem(() => publicMember.access.set(roles.VIEWER), 'On', testId(`um-public-option`)),
|
|
|
|
menuItem(() => publicMember.access.set(null), 'Off',
|
|
|
|
// Disable null access if anonymous access is inherited.
|
|
|
|
dom.cls('disabled', (use) => use(publicMember.inheritedAccess) !== null),
|
|
|
|
testId(`um-public-option`)
|
|
|
|
),
|
|
|
|
// If the 'Off' setting is disabled, show an explanation.
|
|
|
|
dom.maybe((use) => use(publicMember.inheritedAccess) !== null, () => menuText(
|
|
|
|
`Public access inherited from ${getResourceParent(this._model.resourceType)}. ` +
|
|
|
|
`To remove, set 'Inherit access' option to 'None'.`))
|
|
|
|
];
|
|
|
|
}),
|
|
|
|
dom.text((use) => use(publicMember.effectiveAccess) ? 'On' : 'Off'),
|
|
|
|
cssCollapseIcon('Collapse'),
|
|
|
|
testId('um-public-access')
|
|
|
|
),
|
|
|
|
hoverTooltip((ctl) => {
|
|
|
|
tooltipControl = ctl;
|
|
|
|
return 'Allow anyone with the link to open.';
|
|
|
|
}),
|
|
|
|
) : null,
|
|
|
|
),
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build a single member row.
|
|
|
|
private _buildMemberDom(member: IEditableMember) {
|
|
|
|
const disableRemove = Computed.create(null, (use) =>
|
2022-04-12 19:31:41 +00:00
|
|
|
this._model.isPersonal ? !member.origAccess :
|
2020-10-02 15:10:00 +00:00
|
|
|
Boolean(this._model.isActiveUser(member) || use(member.inheritedAccess)));
|
|
|
|
return dom('div',
|
|
|
|
dom.autoDispose(disableRemove),
|
|
|
|
dom.maybe((use) => use(member.effectiveAccess) && use(member.effectiveAccess) !== roles.GUEST, () =>
|
|
|
|
cssMemberListItem(
|
2021-10-25 16:54:04 +00:00
|
|
|
cssMemberListItem.cls('-removed', member.isRemoved),
|
2020-10-02 15:10:00 +00:00
|
|
|
cssMemberImage(
|
|
|
|
createUserImage(getFullUser(member), 'large')
|
|
|
|
),
|
|
|
|
cssMemberText(
|
2022-05-19 04:51:48 +00:00
|
|
|
cssMemberPrimary(
|
|
|
|
member.name || member.email,
|
|
|
|
member.email ? dom.cls('member-email') : null,
|
|
|
|
testId('um-member-name'),
|
|
|
|
),
|
|
|
|
!member.name ? null : cssMemberSecondary(
|
|
|
|
member.email, dom.cls('member-email'), testId('um-member-email')
|
|
|
|
),
|
2022-05-26 06:47:26 +00:00
|
|
|
(this._model.isPersonal
|
|
|
|
? this._buildSelfAnnotationDom(member)
|
|
|
|
: this._buildAnnotationDom(member)
|
2022-05-19 04:51:48 +00:00
|
|
|
),
|
2020-10-02 15:10:00 +00:00
|
|
|
),
|
|
|
|
member.isRemoved ? null : this._memberRoleSelector(member.effectiveAccess,
|
|
|
|
member.inheritedAccess, this._model.isActiveUser(member)),
|
|
|
|
// Only show delete buttons when editing the org users or when a user is being newly
|
|
|
|
// added to any resource. In workspace/doc UserManager instances we want to see all the
|
|
|
|
// users in the org, whether or not they have access to the resource of interest. They may
|
|
|
|
// be denied access via the role dropdown.
|
|
|
|
// Show the undo icon when an item has been removed but its removal has not been saved to
|
|
|
|
// the server.
|
|
|
|
cssMemberBtn(
|
|
|
|
// Button icon.
|
|
|
|
member.isRemoved ? cssUndoIcon('Undo', testId('um-member-undo')) :
|
|
|
|
cssRemoveIcon('Remove', testId('um-member-delete')),
|
|
|
|
cssMemberBtn.cls('-disabled', disableRemove),
|
|
|
|
// Click handler.
|
|
|
|
dom.on('click', () => disableRemove.get() ||
|
|
|
|
(member.isRemoved ? this._model.add(member.email, member.access.get()) :
|
|
|
|
this._model.remove(member)))
|
|
|
|
),
|
|
|
|
testId('um-member')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-05-19 04:51:48 +00:00
|
|
|
// Build an annotation for a single member in the Manage Users dialog.
|
2021-10-25 16:54:04 +00:00
|
|
|
private _buildAnnotationDom(member: IEditableMember) {
|
|
|
|
return dom.domComputed(this._model.annotations, (annotations) => {
|
|
|
|
const annotation = annotations.users.get(member.email);
|
|
|
|
if (!annotation) { return null; }
|
|
|
|
if (annotation.isSupport) {
|
|
|
|
return cssMemberType('Grist support');
|
|
|
|
}
|
|
|
|
if (annotation.isMember && annotations.hasTeam) {
|
|
|
|
return cssMemberType('Team member');
|
|
|
|
}
|
2022-10-05 14:19:28 +00:00
|
|
|
const collaborator = annotations.hasTeam ? 'guest' : 'free collaborator';
|
2021-10-25 16:54:04 +00:00
|
|
|
const limit = annotation.collaboratorLimit;
|
|
|
|
if (!limit || !limit.top) { return null; }
|
|
|
|
const elements: HTMLSpanElement[] = [];
|
|
|
|
if (limit.at <= limit.top) {
|
2022-10-05 14:19:28 +00:00
|
|
|
elements.push(cssMemberType(`${limit.at} of ${limit.top} ${collaborator}s`));
|
2021-10-25 16:54:04 +00:00
|
|
|
} else {
|
2022-10-05 14:19:28 +00:00
|
|
|
elements.push(cssMemberTypeProblem(`${capitalizeFirstWord(collaborator)} limit exceeded`));
|
2021-10-25 16:54:04 +00:00
|
|
|
}
|
|
|
|
if (annotations.hasTeam) {
|
|
|
|
// Add a link for adding a member. For a doc, streamline this so user can make
|
|
|
|
// the change and continue seamlessly.
|
|
|
|
// TODO: streamline for workspaces.
|
|
|
|
elements.push(cssLink(
|
|
|
|
{href: urlState().makeUrl({manageUsers: true})},
|
|
|
|
dom.on('click', (e) => {
|
|
|
|
if (this._options.appModel) {
|
|
|
|
e.preventDefault();
|
|
|
|
manageTeam(this._options.appModel,
|
|
|
|
() => this._model.reloadAnnotations(),
|
|
|
|
{ email: member.email }).catch(reportError);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
`Add ${member.name || 'member'} to your team`));
|
|
|
|
} else if (limit.at >= limit.top) {
|
|
|
|
elements.push(cssLink({href: commonUrls.plans, target: '_blank'},
|
|
|
|
'Create a team to share with more people'));
|
|
|
|
}
|
|
|
|
return elements;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-19 04:51:48 +00:00
|
|
|
// Build an annotation for the current user in the Access Details dialog.
|
|
|
|
private _buildSelfAnnotationDom(user: IEditableMember) {
|
|
|
|
return dom.domComputed(this._model.annotations, (annotations) => {
|
|
|
|
const annotation = annotations.users.get(user.email);
|
|
|
|
if (!annotation) { return null; }
|
|
|
|
|
2022-05-26 06:47:26 +00:00
|
|
|
let memberType: string;
|
2022-05-19 04:51:48 +00:00
|
|
|
if (annotation.isSupport) {
|
2022-05-26 06:47:26 +00:00
|
|
|
memberType = 'Grist support';
|
2022-05-19 04:51:48 +00:00
|
|
|
} else if (annotation.isMember && annotations.hasTeam) {
|
2022-05-26 06:47:26 +00:00
|
|
|
memberType = 'Team member';
|
2022-05-19 04:51:48 +00:00
|
|
|
} else if (annotations.hasTeam) {
|
2022-05-26 06:47:26 +00:00
|
|
|
memberType = 'Outside collaborator';
|
2022-05-19 04:51:48 +00:00
|
|
|
} else {
|
2022-05-26 06:47:26 +00:00
|
|
|
memberType = 'Collaborator';
|
2022-05-19 04:51:48 +00:00
|
|
|
}
|
2022-05-26 06:47:26 +00:00
|
|
|
|
|
|
|
return cssMemberType(memberType, testId('um-member-annotation'));
|
2022-05-19 04:51:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
private _buildPublicAccessMember() {
|
|
|
|
const publicMember = this._model.publicMember;
|
|
|
|
if (!publicMember) { return null; }
|
|
|
|
return dom('div',
|
|
|
|
dom.maybe((use) => Boolean(use(publicMember.effectiveAccess)), () =>
|
|
|
|
cssMemberListItem(
|
|
|
|
cssPublicMemberIcon('PublicFilled'),
|
|
|
|
cssMemberText(
|
|
|
|
cssMemberPrimary('Public Access'),
|
2021-10-25 16:54:04 +00:00
|
|
|
cssMemberSecondary('Anyone with link ', makeCopyBtn(this._options.linkToCopy)),
|
2020-10-02 15:10:00 +00:00
|
|
|
),
|
|
|
|
this._memberRoleSelector(publicMember.effectiveAccess, publicMember.inheritedAccess, false,
|
2022-05-19 04:51:48 +00:00
|
|
|
this._model.publicUserSelectOptions
|
2020-10-02 15:10:00 +00:00
|
|
|
),
|
|
|
|
cssMemberBtn(
|
|
|
|
cssRemoveIcon('Remove', testId('um-member-delete')),
|
|
|
|
dom.on('click', () => publicMember.access.set(null)),
|
|
|
|
),
|
|
|
|
testId('um-public-member')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-05-19 04:51:48 +00:00
|
|
|
private _buildSelfPublicAccessDom() {
|
|
|
|
const accessValue = this._options.resource?.access;
|
|
|
|
const accessLabel = this._model.publicUserSelectOptions
|
|
|
|
.find(opt => opt.value === accessValue)?.label;
|
|
|
|
const activeUser = this._model.activeUser;
|
|
|
|
const name = activeUser?.name ?? 'Anonymous';
|
|
|
|
|
|
|
|
return dom('div',
|
|
|
|
cssMemberListItem(
|
|
|
|
(!activeUser
|
|
|
|
? cssPublicMemberIcon('PublicFilled')
|
|
|
|
: cssMemberImage(createUserImage(activeUser, 'large'))
|
|
|
|
),
|
|
|
|
cssMemberText(
|
|
|
|
cssMemberPrimary(name, testId('um-member-name')),
|
|
|
|
activeUser?.email ? cssMemberSecondary(activeUser.email) : null,
|
|
|
|
cssMemberPublicAccess(
|
|
|
|
dom('span', 'Public access', testId('um-member-annotation')),
|
|
|
|
cssPublicAccessIcon('PublicFilled'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
cssRoleBtn(
|
|
|
|
accessLabel ?? 'Guest',
|
|
|
|
cssCollapseIcon('Collapse'),
|
|
|
|
dom.cls('disabled'),
|
|
|
|
testId('um-member-role'),
|
|
|
|
),
|
|
|
|
testId('um-member'),
|
|
|
|
),
|
|
|
|
testId('um-members'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private _buildSelfAccessDom() {
|
|
|
|
return dom('div',
|
|
|
|
dom.domComputed(this._model.membersEdited, members =>
|
|
|
|
members[0] ? this._buildMemberDom(members[0]) : null
|
|
|
|
),
|
|
|
|
testId('um-members'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// Returns a div containing a button that opens a menu to choose between roles.
|
|
|
|
private _memberRoleSelector(
|
|
|
|
role: Observable<string|null>,
|
|
|
|
inherited: Observable<roles.Role|null>,
|
|
|
|
isActiveUser: boolean,
|
|
|
|
allRolesOverride?: IOrgMemberSelectOption[],
|
|
|
|
) {
|
|
|
|
const allRoles = allRolesOverride ||
|
|
|
|
(this._model.isOrg ? this._model.orgUserSelectOptions : this._model.userSelectOptions);
|
|
|
|
return cssRoleBtn(
|
2022-05-19 04:51:48 +00:00
|
|
|
// Don't include the menu if we're only showing access details for the current user.
|
|
|
|
this._model.isPersonal ? null : menu(() => [
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.forEach(allRoles, _role =>
|
|
|
|
// The active user should be prevented from changing their own role.
|
|
|
|
menuItem(() => isActiveUser || role.set(_role.value), _role.label,
|
|
|
|
// Indicate which option is inherited, if any.
|
|
|
|
dom.text((use) => use(inherited) && (use(inherited) === _role.value)
|
|
|
|
&& !isActiveUser ? ' (inherited)' : ''),
|
|
|
|
// Disable everything providing less access than the inherited access
|
|
|
|
dom.cls('disabled', (use) =>
|
|
|
|
roles.getStrongestRole(_role.value, use(inherited)) !== _role.value),
|
|
|
|
testId(`um-role-option`)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
// If the user's access is inherited, give an explanation on how to change it.
|
|
|
|
isActiveUser ? menuText(`User may not modify their own access.`) : null,
|
|
|
|
// If the user's access is inherited, give an explanation on how to change it.
|
|
|
|
dom.maybe((use) => use(inherited) && !isActiveUser, () => menuText(
|
|
|
|
`User inherits permissions from ${getResourceParent(this._model.resourceType)}. To remove, ` +
|
|
|
|
`set 'Inherit access' option to 'None'.`)),
|
|
|
|
// If the user is a guest, give a description of the guest permission.
|
|
|
|
dom.maybe((use) => !this._model.isOrg && use(role) === roles.GUEST, () => menuText(
|
|
|
|
`User has view access to ${this._model.resourceType} resulting from manually-set access ` +
|
|
|
|
`to resources inside. If removed here, this user will lose access to resources inside.`)),
|
|
|
|
this._model.isOrg ? menuText(`No default access allows access to be ` +
|
|
|
|
`granted to individual documents or workspaces, rather than the full team site.`) : null
|
|
|
|
]),
|
|
|
|
dom.text((use) => {
|
|
|
|
// Get the label of the active role. Note that the 'Guest' role is assigned when the role
|
|
|
|
// is not found because it is not included as a selection.
|
|
|
|
const activeRole = allRoles.find((_role: IOrgMemberSelectOption) => use(role) === _role.value);
|
|
|
|
return activeRole ? activeRole.label : "Guest";
|
|
|
|
}),
|
|
|
|
cssCollapseIcon('Collapse'),
|
2022-05-19 04:51:48 +00:00
|
|
|
this._model.isPersonal ? dom.cls('disabled') : null,
|
2020-10-02 15:10:00 +00:00
|
|
|
testId('um-member-role')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Builds the max inherited role selection button and menu.
|
|
|
|
private _inheritRoleSelector() {
|
|
|
|
const role = this._model.maxInheritedRole;
|
|
|
|
const allRoles = this._model.inheritSelectOptions;
|
|
|
|
return cssOptionBtn(
|
|
|
|
menu(() => [
|
|
|
|
dom.forEach(allRoles, _role =>
|
|
|
|
menuItem(() => role.set(_role.value), _role.label,
|
|
|
|
testId(`um-role-option`)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
dom.text((use) => {
|
|
|
|
// Get the label of the active role.
|
|
|
|
const activeRole = allRoles.find((_role: IMemberSelectOption) => use(role) === _role.value);
|
|
|
|
return activeRole ? activeRole.label : "";
|
|
|
|
}),
|
|
|
|
cssCollapseIcon('Collapse'),
|
|
|
|
testId('um-max-inherited-role')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 14:30:54 +00:00
|
|
|
function getUserItem(member: IEditableMember): ACUserItem {
|
|
|
|
return {
|
|
|
|
value: member.email,
|
|
|
|
label: member.email,
|
|
|
|
cleanText: normalizeText(member.email),
|
|
|
|
email: member.email,
|
|
|
|
name: member.name,
|
|
|
|
picture: member?.picture,
|
|
|
|
id: member.id,
|
2022-09-27 21:06:02 +00:00
|
|
|
};
|
2022-09-21 14:30:54 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* Represents the widget that allows typing in an email and adding it.
|
|
|
|
*/
|
2022-09-21 14:30:54 +00:00
|
|
|
export class ACMemberEmail extends Disposable {
|
|
|
|
private _email = this.autoDispose(observable<string>(""));
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
constructor(
|
2021-10-25 16:54:04 +00:00
|
|
|
private _onAdd: (email: string, role: roles.NonGuestRole) => void,
|
2022-09-21 14:30:54 +00:00
|
|
|
private _members: Array<IEditableMember>,
|
|
|
|
private _prompt?: {email: string}
|
2020-10-02 15:10:00 +00:00
|
|
|
) {
|
|
|
|
super();
|
2021-10-25 16:54:04 +00:00
|
|
|
if (_prompt) {
|
2022-09-21 14:30:54 +00:00
|
|
|
this._email.set(_prompt.email);
|
2021-10-25 16:54:04 +00:00
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 14:30:54 +00:00
|
|
|
public buildDom() {
|
2022-10-17 20:25:15 +00:00
|
|
|
const acUserItem = this._members
|
|
|
|
// Only suggest team members in autocomplete.
|
|
|
|
.filter((member: IEditableMember) => member.isTeamMember)
|
|
|
|
.map((member: IEditableMember) => getUserItem(member));
|
2022-09-21 14:30:54 +00:00
|
|
|
const acIndex = new ACIndexImpl<ACUserItem>(acUserItem);
|
|
|
|
|
|
|
|
return buildACMemberEmail(this,
|
|
|
|
{
|
|
|
|
acIndex,
|
|
|
|
emailObs: this._email,
|
|
|
|
save: this._handleSave.bind(this),
|
|
|
|
prompt: this._prompt,
|
|
|
|
},
|
2020-10-02 15:10:00 +00:00
|
|
|
testId('um-member-new')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-21 14:30:54 +00:00
|
|
|
private _handleSave(selectedEmail: string) {
|
2022-09-27 21:06:02 +00:00
|
|
|
this._onAdd(selectedEmail, roles.VIEWER);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a new FullUser object from an IEditableMember.
|
|
|
|
function getFullUser(member: IEditableMember): FullUser {
|
|
|
|
return {
|
|
|
|
id: member.id,
|
|
|
|
name: member.name,
|
|
|
|
email: member.email,
|
2023-01-24 13:13:18 +00:00
|
|
|
picture: member.picture,
|
|
|
|
locale: member.locale
|
2020-10-02 15:10:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a "Copy Link" button.
|
2020-11-26 02:29:13 +00:00
|
|
|
function makeCopyBtn(linkToCopy: string|undefined, ...domArgs: DomElementArg[]) {
|
|
|
|
return linkToCopy && cssCopyBtn(cssCopyIcon('Copy'), 'Copy Link',
|
|
|
|
dom.on('click', (ev, elem) => copyLink(elem, linkToCopy)),
|
2020-10-02 15:10:00 +00:00
|
|
|
testId('um-copy-link'),
|
|
|
|
...domArgs,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the current document link to clipboard, and notify the user with a transient popup near
|
|
|
|
// the given element.
|
2020-11-26 02:29:13 +00:00
|
|
|
async function copyLink(elem: HTMLElement, link: string) {
|
2020-10-02 15:10:00 +00:00
|
|
|
await copyToClipboard(link);
|
|
|
|
setTestState({clipboard: link});
|
|
|
|
showTransientTooltip(elem, 'Link copied to clipboard', {key: 'copy-doc-link'});
|
|
|
|
}
|
|
|
|
|
2021-10-25 16:54:04 +00:00
|
|
|
async function manageTeam(appModel: AppModel,
|
|
|
|
onSave?: () => Promise<void>,
|
|
|
|
prompt?: { email: string }) {
|
|
|
|
await urlState().pushUrl({manageUsers: false});
|
|
|
|
const user = appModel.currentValidUser;
|
|
|
|
const currentOrg = appModel.currentOrg;
|
|
|
|
if (currentOrg) {
|
|
|
|
const api = appModel.api;
|
|
|
|
showUserManagerModal(api, {
|
|
|
|
permissionData: api.getOrgAccess(currentOrg.id),
|
2022-05-19 04:51:48 +00:00
|
|
|
activeUser: user,
|
2021-10-25 16:54:04 +00:00
|
|
|
resourceType: 'organization',
|
|
|
|
resourceId: currentOrg.id,
|
2021-11-05 14:47:17 +00:00
|
|
|
resource: currentOrg,
|
2021-10-25 16:54:04 +00:00
|
|
|
onSave,
|
|
|
|
prompt,
|
2021-11-05 14:47:17 +00:00
|
|
|
showAnimation: true,
|
2021-10-25 16:54:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-19 04:51:48 +00:00
|
|
|
const cssAccessDetailsBody = styled('div', `
|
2020-10-02 15:10:00 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
width: 600px;
|
2022-05-19 04:51:48 +00:00
|
|
|
font-size: ${vars.mediumFontSize};
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssUserManagerBody = styled(cssAccessDetailsBody, `
|
2020-10-02 15:10:00 +00:00
|
|
|
height: 374px;
|
2022-09-06 01:51:57 +00:00
|
|
|
border-bottom: 1px solid ${theme.modalBorderDark};
|
2022-05-19 04:51:48 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
const cssSpinner = styled('div', `
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
margin: 32px;
|
2020-10-02 15:10:00 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
const cssCopyBtn = styled(basicButton, `
|
|
|
|
border: none;
|
|
|
|
font-weight: normal;
|
|
|
|
padding: 0 8px;
|
|
|
|
&-header {
|
|
|
|
float: right;
|
|
|
|
margin-top: 8px;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssCopyIcon = styled(icon, `
|
|
|
|
margin-right: 4px;
|
|
|
|
margin-top: -2px;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssOptionRow = styled('div', `
|
|
|
|
font-size: ${vars.mediumFontSize};
|
|
|
|
margin: 0 63px 23px 63px;
|
|
|
|
`);
|
|
|
|
|
2022-11-28 14:02:32 +00:00
|
|
|
const cssOptionRowMultiple = styled('div', `
|
|
|
|
margin: 0 63px 12px 63px;
|
|
|
|
font-size: ${vars.mediumFontSize};
|
|
|
|
display: flex;
|
|
|
|
cursor: pointer;
|
|
|
|
color: ${theme.controlFg};
|
|
|
|
--icon-color: ${theme.controlFg};
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: ${theme.controlHoverFg};
|
|
|
|
--icon-color: ${theme.controlHoverFg};
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssLabel = styled('span', `
|
|
|
|
margin-left: 4px;
|
|
|
|
`);
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
const cssOptionBtn = styled('span', `
|
|
|
|
display: inline-flex;
|
|
|
|
font-size: ${vars.mediumFontSize};
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.controlFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
cursor: pointer;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssPublicMemberIcon = styled(icon, `
|
2022-05-19 04:51:48 +00:00
|
|
|
width: 40px;
|
|
|
|
height: 40px;
|
|
|
|
margin: 0 4px;
|
2022-09-06 01:51:57 +00:00
|
|
|
--icon-color: ${theme.accentIcon};
|
2022-05-19 04:51:48 +00:00
|
|
|
`);
|
|
|
|
|
2022-10-19 23:06:05 +00:00
|
|
|
const cssSmallPublicMemberIcon = styled(cssPublicMemberIcon, `
|
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
top: -2px;
|
|
|
|
`);
|
|
|
|
|
2022-05-19 04:51:48 +00:00
|
|
|
const cssPublicAccessIcon = styled(icon, `
|
2022-09-06 01:51:57 +00:00
|
|
|
--icon-color: ${theme.accentIcon};
|
2020-10-02 15:10:00 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
const cssUndoIcon = styled(icon, `
|
2022-09-06 01:51:57 +00:00
|
|
|
--icon-color: ${theme.controlSecondaryFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
margin: 12px 0;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssRoleBtn = styled('div', `
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
font-size: ${vars.mediumFontSize};
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.controlFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
margin: 12px 24px;
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&.disabled {
|
2022-05-19 04:51:48 +00:00
|
|
|
opacity: 0.5;
|
2020-10-02 15:10:00 +00:00
|
|
|
cursor: default;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssCollapseIcon = styled(icon, `
|
|
|
|
margin-top: 1px;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
`);
|
|
|
|
|
2020-12-04 23:29:29 +00:00
|
|
|
const cssAccessLink = styled(cssLink, `
|
|
|
|
align-self: center;
|
|
|
|
margin-left: auto;
|
2020-10-02 15:10:00 +00:00
|
|
|
`);
|
|
|
|
|
2021-11-05 14:47:17 +00:00
|
|
|
const cssOrgName = styled('div', `
|
|
|
|
font-size: ${vars.largeFontSize};
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssOrgDomain = styled('span', `
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.accentText};
|
2021-11-05 14:47:17 +00:00
|
|
|
`);
|
|
|
|
|
2022-05-19 04:51:48 +00:00
|
|
|
const cssTitle = styled(cssModalTitle, `
|
|
|
|
margin: 40px 64px 0 64px;
|
|
|
|
|
|
|
|
@media ${mediaXSmall} {
|
|
|
|
& {
|
|
|
|
margin: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssMemberPublicAccess = styled(cssMemberSecondary, `
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: 8px;
|
|
|
|
`);
|
|
|
|
|
2021-11-05 14:47:17 +00:00
|
|
|
// Render the UserManager title for `resourceType` (e.g. org as "team site").
|
2022-04-12 19:31:41 +00:00
|
|
|
function renderTitle(resourceType: ResourceType, resource?: Resource, personal?: boolean) {
|
2021-11-05 14:47:17 +00:00
|
|
|
switch (resourceType) {
|
|
|
|
case 'organization': {
|
2022-04-12 19:31:41 +00:00
|
|
|
if (personal) { return 'Your role for this team site'; }
|
2021-11-05 14:47:17 +00:00
|
|
|
return [
|
|
|
|
'Manage members of team site',
|
|
|
|
!resource ? null : cssOrgName(
|
|
|
|
`${(resource as Organization).name} (`,
|
|
|
|
cssOrgDomain(`${(resource as Organization).domain}.getgrist.com`),
|
|
|
|
')',
|
|
|
|
)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
default: {
|
2022-04-12 19:31:41 +00:00
|
|
|
return personal ? `Your role for this ${resourceType}` : `Invite people to ${resourceType}`;
|
2021-11-05 14:47:17 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
2022-04-12 19:31:41 +00:00
|
|
|
|
|
|
|
// Rename organization to team site.
|
|
|
|
function resourceName(resourceType: ResourceType): string {
|
|
|
|
return resourceType === 'organization' ? 'team site' : resourceType;
|
|
|
|
}
|