🛠️ Shared with me feature flag (#681)

🛠️ Shared with me feature flag (#681)
This commit is contained in:
Montassar Ghanmy
2024-10-10 13:28:24 +01:00
committed by GitHub
parent b3b80ede84
commit 9003944bb2
11 changed files with 132 additions and 41 deletions
@@ -79,6 +79,9 @@ export class DocumentsService {
defaultQuota: number = config.has("drive.defaultUserQuota")
? config.get("drive.defaultUserQuota")
: 0;
manageAccessEnabled: boolean = config.has("drive.featureManageAccess")
? config.get("drive.featureManageAccess")
: false;
logger: TdriveLogger = getLogger("Documents Service");
async init(): Promise<this> {
@@ -556,33 +559,38 @@ export class DocumentsService {
oldParent = item.parent_id;
}
if (key === "access_info") {
const sharedWith = content.access_info.entities.filter(
info =>
info.type === "user" &&
info.id !== context.user.id &&
!item.access_info.entities.find(entity => entity.id === info.id),
);
// if manage access is disabled, we don't allow changing access level
if (!this.manageAccessEnabled) {
delete content.access_info;
} else if (content.access_info) {
const sharedWith = content.access_info.entities.filter(
info =>
info.type === "user" &&
info.id !== context.user.id &&
!item.access_info.entities.find(entity => entity.id === info.id),
);
item.access_info = content.access_info;
item.access_info = content.access_info;
if (sharedWith.length > 0) {
// Notify the user that the document has been shared with them
this.logger.info("Notifying user that the document has been shared with them: ", {
sharedWith,
});
gr.services.documents.engine.notifyDocumentShared({
context,
item,
notificationEmitter: context.user.id,
notificationReceiver: sharedWith[0].id,
if (sharedWith.length > 0) {
// Notify the user that the document has been shared with them
this.logger.info("Notifying user that the document has been shared with them: ", {
sharedWith,
});
gr.services.documents.engine.notifyDocumentShared({
context,
item,
notificationEmitter: context.user.id,
notificationReceiver: sharedWith[0].id,
});
}
item.access_info.entities.forEach(info => {
if (!info.grantor) {
info.grantor = context.user.id;
}
});
}
item.access_info.entities.forEach(info => {
if (!info.grantor) {
info.grantor = context.user.id;
}
});
} else if (key === "name") {
renamedTo = item.name = await getItemName(
content.parent_id || item.parent_id,
@@ -54,10 +54,6 @@ export function formatCompany(
[CompanyFeaturesEnum.CHAT_EDIT_FILES]: true,
[CompanyFeaturesEnum.CHAT_UNLIMITED_STORAGE]: true,
[CompanyFeaturesEnum.COMPANY_INVITE_MEMBER]: true,
// use the config value for this one
[CompanyFeaturesEnum.COMPANY_SEARCH_USERS]: JSON.parse(
config.get("drive.featureSearchUsers") || "true",
),
[CompanyFeaturesEnum.COMPANY_SHARED_DRIVE]: JSON.parse(
config.get("drive.featureSharedDrive") || "true",
),
@@ -67,6 +63,9 @@ export function formatCompany(
[CompanyFeaturesEnum.COMPANY_USER_QUOTA]: JSON.parse(
config.get("drive.featureUserQuota") || "false",
),
[CompanyFeaturesEnum.COMPANY_MANAGE_ACCESS]: JSON.parse(
config.get("drive.featureManageAccess") || "true",
),
},
{
...(res.plan?.features || {}),
@@ -76,8 +75,6 @@ export function formatCompany(
},
);
console.log("🚀🚀 res.plan.features: ", res.plan.features);
return res;
}
@@ -91,10 +91,10 @@ export const companyObjectSchema = {
[CompanyFeaturesEnum.CHAT_MULTIPLE_WORKSPACES]: { type: "boolean" },
[CompanyFeaturesEnum.CHAT_UNLIMITED_STORAGE]: { type: "boolean" },
[CompanyFeaturesEnum.COMPANY_INVITE_MEMBER]: { type: "boolean" },
[CompanyFeaturesEnum.COMPANY_SEARCH_USERS]: { type: "boolean" },
[CompanyFeaturesEnum.COMPANY_SHARED_DRIVE]: { type: "boolean" },
[CompanyFeaturesEnum.COMPANY_DISPLAY_EMAIL]: { type: "boolean" },
[CompanyFeaturesEnum.COMPANY_USER_QUOTA]: { type: "boolean" },
[CompanyFeaturesEnum.COMPANY_MANAGE_ACCESS]: { type: "boolean" },
guests: { type: "number" }, // to rename or delete
members: { type: "number" }, // to rename or delete
storage: { type: "number" }, // to rename or delete
@@ -83,10 +83,10 @@ export enum CompanyFeaturesEnum {
CHAT_EDIT_FILES = "chat:edit_files",
CHAT_UNLIMITED_STORAGE = "chat:unlimited_storage",
COMPANY_INVITE_MEMBER = "company:invite_member",
COMPANY_SEARCH_USERS = "company:search_users",
COMPANY_SHARED_DRIVE = "company:shared_drive",
COMPANY_DISPLAY_EMAIL = "company:display_email",
COMPANY_USER_QUOTA = "company:user_quota",
COMPANY_MANAGE_ACCESS = "company:managed_access",
}
export type CompanyFeaturesObject = {
@@ -96,10 +96,10 @@ export type CompanyFeaturesObject = {
[CompanyFeaturesEnum.CHAT_EDIT_FILES]?: boolean;
[CompanyFeaturesEnum.CHAT_UNLIMITED_STORAGE]?: boolean;
[CompanyFeaturesEnum.COMPANY_INVITE_MEMBER]?: boolean;
[CompanyFeaturesEnum.COMPANY_SEARCH_USERS]?: boolean;
[CompanyFeaturesEnum.COMPANY_SHARED_DRIVE]?: boolean;
[CompanyFeaturesEnum.COMPANY_DISPLAY_EMAIL]?: boolean;
[CompanyFeaturesEnum.COMPANY_USER_QUOTA]?: boolean;
[CompanyFeaturesEnum.COMPANY_MANAGE_ACCESS]?: boolean;
};
export type CompanyLimitsObject = {