🕹 Manage root users default role (#180)
🕹 Manage root users default role
This commit is contained in:
@@ -22,7 +22,8 @@ import User, { getInstance } from "../../user/entities/user";
|
||||
import { getInstance as getCompanyInstance } from "../../user/entities/company";
|
||||
import { ConsoleServiceImpl } from "../service";
|
||||
import coalesce from "../../../utils/coalesce";
|
||||
|
||||
import config from "config";
|
||||
import { CompanyUserRole } from "src/services/user/web/types";
|
||||
export class ConsoleRemoteClient implements ConsoleServiceClient {
|
||||
version: "1";
|
||||
client: AxiosInstance;
|
||||
@@ -30,6 +31,10 @@ export class ConsoleRemoteClient implements ConsoleServiceClient {
|
||||
private infos: ConsoleOptions;
|
||||
private verifier: OidcJwtVerifier;
|
||||
|
||||
private rootAdmins: string[] = config.has("drive.rootAdmins")
|
||||
? config.get("drive.rootAdmins")
|
||||
: [];
|
||||
|
||||
constructor(consoleInstance: ConsoleServiceImpl) {
|
||||
this.infos = consoleInstance.consoleOptions;
|
||||
this.verifier = new OidcJwtVerifier({
|
||||
@@ -167,7 +172,12 @@ export class ConsoleRemoteClient implements ConsoleServiceClient {
|
||||
);
|
||||
}
|
||||
|
||||
await gr.services.companies.setUserRole(company.id, user.id, "admin");
|
||||
let userRole: CompanyUserRole = "member";
|
||||
if (this.rootAdmins.includes(userDTO.email)) {
|
||||
userRole = "admin";
|
||||
}
|
||||
|
||||
await gr.services.companies.setUserRole(company.id, user.id, userRole);
|
||||
|
||||
await gr.services.users.save(user, { user: { id: user.id, server_request: true } });
|
||||
|
||||
|
||||
@@ -22,9 +22,14 @@ import { getInstance as getCompanyInstance } from "../../../services/user/entiti
|
||||
import Workspace from "../../../services/workspaces/entities/workspace";
|
||||
import gr from "../../global-resolver";
|
||||
import { Configuration } from "../../../core/platform/framework";
|
||||
import { CompanyUserRole } from "src/services/user/web/types";
|
||||
import config from "config";
|
||||
|
||||
export class ConsoleController {
|
||||
private passwordEncoder: PasswordEncoder;
|
||||
private rootAdmins: string[] = config.has("drive.rootAdmins")
|
||||
? config.get("drive.rootAdmins")
|
||||
: [];
|
||||
|
||||
constructor() {
|
||||
this.passwordEncoder = new PasswordEncoder();
|
||||
@@ -72,6 +77,7 @@ export class ConsoleController {
|
||||
email_canonical: email,
|
||||
username_canonical: (email.replace("@", ".") || "").toLocaleLowerCase(),
|
||||
});
|
||||
let userRole: CompanyUserRole = "member";
|
||||
const user = await gr.services.users.create(newUser);
|
||||
await gr.services.users.setPassword({ id: user.entity.id }, request.body.password);
|
||||
|
||||
@@ -85,7 +91,10 @@ export class ConsoleController {
|
||||
});
|
||||
company = await gr.services.companies.createCompany(newCompany);
|
||||
}
|
||||
await gr.services.companies.setUserRole(company.id, user.entity.id, "admin");
|
||||
if (this.rootAdmins.includes(email)) {
|
||||
userRole = "admin";
|
||||
}
|
||||
await gr.services.companies.setUserRole(company.id, user.entity.id, userRole);
|
||||
|
||||
//In case someone invited us to a workspace
|
||||
await gr.services.workspaces.processPendingUser(user.entity);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { Modal } from '@atoms/modal';
|
||||
import Avatar from '@atoms/avatar';
|
||||
import { Base, Info } from '@atoms/text';
|
||||
@@ -10,6 +11,7 @@ import currentUserService from '@features/users/services/current-user-service';
|
||||
import { useUserCompanyList } from '@features/users/hooks/use-user-company-list';
|
||||
import { AccessLevel } from './common';
|
||||
import Languages from 'features/global/services/languages-service';
|
||||
import { DriveFileAccessLevel } from 'app/features/drive/types';
|
||||
|
||||
export type UsersModalType = {
|
||||
open: boolean;
|
||||
@@ -54,7 +56,8 @@ const UserAccessLevel = ({
|
||||
const user = useUser(userId);
|
||||
const { user: currentUser } = useCurrentUser();
|
||||
const { item, loading, updateLevel } = useDriveItem(id);
|
||||
const level = role == "admin" ? "manage" : "read";
|
||||
const [level, setLevel] = useState<DriveFileAccessLevel>(role == "admin" ? "manage" : "read");
|
||||
//const level = role == "admin" ? "manage" : "read";
|
||||
|
||||
return (
|
||||
<div className="p-4 border-t flex flex-row items-center justify-center">
|
||||
@@ -73,11 +76,12 @@ const UserAccessLevel = ({
|
||||
</div>
|
||||
<div className="shrink-0 ml-2">
|
||||
<AccessLevel
|
||||
disabled={user?.id === currentUser?.id}
|
||||
disabled={userId === currentUser?.id}
|
||||
level={level}
|
||||
canRemove
|
||||
onChange={level => {
|
||||
updateLevel(user?.id || '', level);
|
||||
setLevel(level);
|
||||
updateLevel(userId || '', level);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user