mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) Allowing non-owner managers to add other managers
Summary: Billing managers can now add other billing managers. Before only managers with owner access could do that. Test Plan: Added test Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D4339
This commit is contained in:
parent
963e26dda6
commit
51acc9a8cc
@ -1,5 +1,5 @@
|
|||||||
import {colors, theme} from 'app/client/ui2018/cssVars';
|
import {colors, theme} from 'app/client/ui2018/cssVars';
|
||||||
import {FullUser} from 'app/common/LoginSessionAPI';
|
import {UserProfile} from 'app/common/LoginSessionAPI';
|
||||||
import {dom, DomElementArg, styled} from 'grainjs';
|
import {dom, DomElementArg, styled} from 'grainjs';
|
||||||
import {icon} from 'app/client/ui2018/icons';
|
import {icon} from 'app/client/ui2018/icons';
|
||||||
|
|
||||||
@ -9,7 +9,9 @@ export type Size = 'small' | 'medium' | 'large';
|
|||||||
* Returns a DOM element showing a circular icon with a user's picture, or the user's initials if
|
* Returns a DOM element showing a circular icon with a user's picture, or the user's initials if
|
||||||
* picture is missing. Also varies the color of the circle when using initials.
|
* picture is missing. Also varies the color of the circle when using initials.
|
||||||
*/
|
*/
|
||||||
export function createUserImage(user: FullUser|'exampleUser'|null, size: Size, ...args: DomElementArg[]): HTMLElement {
|
export function createUserImage(
|
||||||
|
user: UserProfile|'exampleUser'|null, size: Size, ...args: DomElementArg[]
|
||||||
|
): HTMLElement {
|
||||||
let initials: string;
|
let initials: string;
|
||||||
return cssUserImage(
|
return cssUserImage(
|
||||||
cssUserImage.cls('-' + size),
|
cssUserImage.cls('-' + size),
|
||||||
@ -39,7 +41,7 @@ export function getInitials(user: {name?: string, email?: string}) {
|
|||||||
/**
|
/**
|
||||||
* Hashes the username to return a color.
|
* Hashes the username to return a color.
|
||||||
*/
|
*/
|
||||||
function pickColor(user: FullUser): string {
|
function pickColor(user: UserProfile): string {
|
||||||
let c = hashCode(user.name + ':' + user.email) % someColors.length;
|
let c = hashCode(user.name + ':' + user.email) % someColors.length;
|
||||||
if (c < 0) { c += someColors.length; }
|
if (c < 0) { c += someColors.length; }
|
||||||
return someColors[c];
|
return someColors[c];
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import {normalizeEmail} from 'app/common/emails';
|
||||||
import {UserPrefs} from 'app/common/Prefs';
|
import {UserPrefs} from 'app/common/Prefs';
|
||||||
|
|
||||||
// User profile info for the user. When using Cognito, it is fetched during login.
|
// User profile info for the user. When using Cognito, it is fetched during login.
|
||||||
@ -12,6 +13,21 @@ export interface UserProfile {
|
|||||||
locale?: string|null;
|
locale?: string|null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to compare two user profiles to see if they represent the same user.
|
||||||
|
* Note: if you have access to FullUser objects, comparing ids is more reliable.
|
||||||
|
*/
|
||||||
|
export function sameUser(a: UserProfile|FullUser, b: UserProfile|FullUser): boolean {
|
||||||
|
if ('id' in a && 'id' in b) {
|
||||||
|
return a.id === b.id;
|
||||||
|
}
|
||||||
|
if (a.loginEmail && b.loginEmail) {
|
||||||
|
return a.loginEmail === b.loginEmail;
|
||||||
|
} else {
|
||||||
|
return normalizeEmail(a.email) === normalizeEmail(b.email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// User profile including user id and user ref. All information in it should
|
// User profile including user id and user ref. All information in it should
|
||||||
// have been validated against database.
|
// have been validated against database.
|
||||||
export interface FullUser extends UserProfile {
|
export interface FullUser extends UserProfile {
|
||||||
|
@ -2031,9 +2031,10 @@ export enum TestUserEnum {
|
|||||||
support = 'support',
|
support = 'support',
|
||||||
}
|
}
|
||||||
export type TestUser = keyof typeof TestUserEnum; // 'user1' | 'user2' | ...
|
export type TestUser = keyof typeof TestUserEnum; // 'user1' | 'user2' | ...
|
||||||
|
export interface UserData { email: string, name: string }
|
||||||
|
|
||||||
// Get name and email for the given test user.
|
// Get name and email for the given test user.
|
||||||
export function translateUser(userName: TestUser): {email: string, name: string} {
|
export function translateUser(userName: TestUser): UserData {
|
||||||
if (userName === 'anon') {
|
if (userName === 'anon') {
|
||||||
return {email: 'anon@getgrist.com', name: 'Anonymous'};
|
return {email: 'anon@getgrist.com', name: 'Anonymous'};
|
||||||
}
|
}
|
||||||
@ -2102,8 +2103,11 @@ export class Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return a session configured for the current session's site but a different user.
|
// Return a session configured for the current session's site but a different user.
|
||||||
public user(userName: TestUser = 'user1') {
|
public user(userName?: TestUser): Session
|
||||||
return new Session({...this.settings, ...translateUser(userName)});
|
public user(user: UserData): Session
|
||||||
|
public user(arg: TestUser|UserData = 'user1') {
|
||||||
|
const data = typeof arg === 'string' ? translateUser(arg) : arg;
|
||||||
|
return new Session({...this.settings, ...data});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a session configured for the current session's site and anonymous access.
|
// Return a session configured for the current session's site and anonymous access.
|
||||||
|
Loading…
Reference in New Issue
Block a user