Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

152 create a permission group for users #154

Merged
merged 6 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ https://cdisc-org.github.io/conformance-rules-editor/
"SWA_TENANT_ID": "<Static Web App Tenant ID>",
"SWA_CLIENT_ID": "<Static Web App Client ID>",
"SWA_CLIENT_SECRET": "<Static Web App Client Secret>",
"CORE_AUTHOR_GROUP": "<User Group ID for write permissions>"
}
}
```
Expand Down
18 changes: 18 additions & 0 deletions api/get_permissions/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": ["get"],
"route": "permissions"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/get_permissions/index.js"
}
16 changes: 16 additions & 0 deletions api/get_permissions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { USERS_PROVIDER } from "../providers/BaseUsers";
import handle_response from "../utils/handle_response";

export default async (context, req) => {
const user = JSON.parse(
Buffer.from(req.headers["x-ms-client-principal"], "base64").toString(
"ascii"
)
);
await handle_response(context, async () => ({
body: await USERS_PROVIDER.getUserPermissions({
id: user.userId,
name: user.userDetails,
}),
}));
};
12 changes: 12 additions & 0 deletions api/providers/MSGraphUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,19 @@ const getUsersByName = async (name: string): Promise<IUser[]> => {
return users;
};

const getUserPermissions = async (user: IUser): Promise<IUser> => {
if ("CORE_AUTHOR_GROUP" in process.env) {
var link = `/users/${user.id}/memberOf?$count=true&$filter=id eq '${process.env["CORE_AUTHOR_GROUP"]}'`;
const response = await client.api(link).get();
user.write_allowed = response.value && response.value.length === 1;
} else {
user.write_allowed = true;
}
return user;
};

export default {
getUsersByIds,
getUsersByName,
getUserPermissions,
};
1 change: 1 addition & 0 deletions api/types/IUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface IUser {
id: string;
name?: string;
company?: string;
write_allowed?: boolean;
}
1 change: 1 addition & 0 deletions api/types/IUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { IUser } from "./IUser";
export interface IUsers {
getUsersByIds: (ids: string[]) => Promise<{ [id: string]: IUser }>;
getUsersByName: (name: string) => Promise<IUser[]>;
getUserPermissions: (user: IUser) => Promise<IUser>;
}
49 changes: 26 additions & 23 deletions docs/dev/doc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/dev/doc.yuml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
[Base Storage Provider|Get-Rules();Get-Rule();Post-Rule();Patch-Rule();Delete-Rule();Max-CoreId();{bg:orange}]
[Drupal Storage{bg:orange}]
[Cosmos SQL Storage{bg:orange}]
[Base Users Provider|Get-Users-By-Ids();Get-Users-By-Name();{bg:orange}]
[Base Users Provider|Get-Users-By-Ids();Get-Users-By-Name();Get-User-Permissions();{bg:orange}]
[MS Graph Users{bg:orange}]

// Azure SWA
Expand All @@ -36,7 +36,7 @@

// Users
[Users|id]
[User|id;name]
[User|id;name;company;write_allowed]

// RELATIONSHIPS

Expand Down
Loading