Skip to content

[server/fga] improved api and code-gen #18376

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

Closed
wants to merge 1 commit into from
Closed
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
355 changes: 63 additions & 292 deletions components/server/src/authorization/authorizer.ts

Large diffs are not rendered by default.

267 changes: 267 additions & 0 deletions components/server/src/authorization/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* See License.AGPL.txt in the project root for license information.
*/

import { v1 } from "@authzed/authzed-node";

export const InstallationID = "1";

export type ResourceType = UserResourceType | InstallationResourceType | OrganizationResourceType | ProjectResourceType;

export type Relation = UserRelation | InstallationRelation | OrganizationRelation | ProjectRelation;
Expand Down Expand Up @@ -50,3 +53,267 @@ export type ProjectResourceType = "project";
export type ProjectRelation = "org" | "editor" | "viewer";

export type ProjectPermission = "read_info" | "write_info" | "delete";

export const rel = {
user(id: string) {
const result: Partial<v1.Relationship> = {
resource: {
objectType: "user",
objectId: id,
},
};
return {
get self() {
const result2 = {
...result,
relation: "self",
};
return {
user(objectId: string) {
return {
...result2,
subject: {
object: {
objectType: "user",
objectId: objectId,
},
},
} as v1.Relationship;
},
};
},

get container() {
const result2 = {
...result,
relation: "container",
};
return {
organization(objectId: string) {
return {
...result2,
subject: {
object: {
objectType: "organization",
objectId: objectId,
},
},
} as v1.Relationship;
},
get installation() {
return {
...result2,
subject: {
object: {
objectType: "installation",
objectId: "1",
},
},
} as v1.Relationship;
},
};
},
};
},

get installation() {
const result: Partial<v1.Relationship> = {
resource: {
objectType: "installation",
objectId: "1",
},
};
return {
get member() {
const result2 = {
...result,
relation: "member",
};
return {
user(objectId: string) {
return {
...result2,
subject: {
object: {
objectType: "user",
objectId: objectId,
},
},
} as v1.Relationship;
},
};
},

get admin() {
const result2 = {
...result,
relation: "admin",
};
return {
user(objectId: string) {
return {
...result2,
subject: {
object: {
objectType: "user",
objectId: objectId,
},
},
} as v1.Relationship;
},
};
},
};
},

organization(id: string) {
const result: Partial<v1.Relationship> = {
resource: {
objectType: "organization",
objectId: id,
},
};
return {
get installation() {
const result2 = {
...result,
relation: "installation",
};
return {
get installation() {
return {
...result2,
subject: {
object: {
objectType: "installation",
objectId: "1",
},
},
} as v1.Relationship;
},
};
},

get member() {
const result2 = {
...result,
relation: "member",
};
return {
user(objectId: string) {
return {
...result2,
subject: {
object: {
objectType: "user",
objectId: objectId,
},
},
} as v1.Relationship;
},
};
},

get owner() {
const result2 = {
...result,
relation: "owner",
};
return {
user(objectId: string) {
return {
...result2,
subject: {
object: {
objectType: "user",
objectId: objectId,
},
},
} as v1.Relationship;
},
};
},
};
},

project(id: string) {
const result: Partial<v1.Relationship> = {
resource: {
objectType: "project",
objectId: id,
},
};
return {
get org() {
const result2 = {
...result,
relation: "org",
};
return {
organization(objectId: string) {
return {
...result2,
subject: {
object: {
objectType: "organization",
objectId: objectId,
},
},
} as v1.Relationship;
},
};
},

get editor() {
const result2 = {
...result,
relation: "editor",
};
return {
user(objectId: string) {
return {
...result2,
subject: {
object: {
objectType: "user",
objectId: objectId,
},
},
} as v1.Relationship;
},
};
},

get viewer() {
const result2 = {
...result,
relation: "viewer",
};
return {
user(objectId: string) {
return {
...result2,
subject: {
object: {
objectType: "user",
objectId: objectId,
},
},
} as v1.Relationship;
},
organization(objectId: string) {
return {
...result2,
subject: {
object: {
objectType: "organization",
objectId: objectId,
},
},
} as v1.Relationship;
},
};
},
};
},
};
Loading