🛠 Allow applications to manage the drive (#59)

* Now applications can manage the drive as they wish

* Fix typo

* Fix the access computation

* Test if my code is the issue

* Fix test if app exists

* Fix test if app exists

* Fix test if app exists
This commit is contained in:
Romaric Mourgues
2023-05-22 13:16:51 +02:00
committed by GitHub
parent 4af8e43bb2
commit 62f3b562c0
7 changed files with 124 additions and 15 deletions
@@ -162,6 +162,20 @@ export const hasAccessLevel = (
* @returns {Promise<boolean>}
*/
export const isCompanyGuest = async (context: CompanyExecutionContext): Promise<boolean> => {
if (context.user?.application_id) {
//Applications do everything (if they are added to the company)
if (
!!(
await globalResolver.services.applications.companyApps.get({
company_id: context.company.id,
application_id: context.user?.application_id,
})
)?.application?.id
) {
return false;
}
}
const userRole = await globalResolver.services.companies.getUserRole(
context.company.id,
context.user?.id,
@@ -177,6 +191,20 @@ export const isCompanyGuest = async (context: CompanyExecutionContext): Promise<
* @returns {Promise<boolean>}
*/
export const isCompanyAdmin = async (context: CompanyExecutionContext): Promise<boolean> => {
if (context.user?.application_id) {
//Applications do everything (if they are added to the company)
if (
!!(
await globalResolver.services.applications.companyApps.get({
company_id: context.company.id,
application_id: context.user?.application_id,
})
)?.application?.id
) {
return true;
}
}
const userRole = await globalResolver.services.companies.getUserRole(
context.company.id,
context.user?.id,
@@ -373,6 +401,20 @@ export const getAccessLevel = async (
throw Error("Drive item doesn't exist");
}
if (context.user?.application_id) {
//Applications do everything (if they are added to the company)
if (
!!(
await globalResolver.services.applications.companyApps.get({
company_id: context.company.id,
application_id: context.user?.application_id,
})
)?.application?.id
) {
return "manage";
}
}
/*
* Specific user or channel rule is applied first. Then less restrictive level will be chosen
* between the parent folder and company accesses.
@@ -673,7 +715,7 @@ export const getFileMetadata = async (
company_id: context.company.id,
},
context,
{ ...(context.user.server_request ? {} : { waitForThumbnail: true }) },
{ ...(context.user?.server_request ? {} : { waitForThumbnail: true }) },
);
if (!file) {