Skip to content

Commit

Permalink
feat(workspaces): add workspaceRole to LimitedUser type (#3721)
Browse files Browse the repository at this point in the history
* feat(workspaces): add workspaceRole to LimitedUser type

* fix(users): require workspace access for query
  • Loading branch information
cdriesler authored Jan 9, 2025
1 parent 58a6795 commit a784a72
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/frontend-2/lib/common/generated/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ export type LimitedUser = {
totalOwnedStreamsFavorites: Scalars['Int']['output'];
verified?: Maybe<Scalars['Boolean']['output']>;
workspaceDomainPolicyCompliant?: Maybe<Scalars['Boolean']['output']>;
workspaceRole?: Maybe<Scalars['String']['output']>;
};


Expand Down Expand Up @@ -1114,6 +1115,15 @@ export type LimitedUserWorkspaceDomainPolicyCompliantArgs = {
workspaceId?: InputMaybe<Scalars['String']['input']>;
};


/**
* Limited user type, for showing public info about a user
* to another user
*/
export type LimitedUserWorkspaceRoleArgs = {
workspaceId?: InputMaybe<Scalars['String']['input']>;
};

/** Workspace metadata visible to non-workspace members. */
export type LimitedWorkspace = {
__typename?: 'LimitedWorkspace';
Expand Down Expand Up @@ -7295,6 +7305,7 @@ export type LimitedUserFieldArgs = {
totalOwnedStreamsFavorites: {},
verified: {},
workspaceDomainPolicyCompliant: LimitedUserWorkspaceDomainPolicyCompliantArgs,
workspaceRole: LimitedUserWorkspaceRoleArgs,
}
export type LimitedWorkspaceFieldArgs = {
defaultLogoIndex: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ extend type Project {
# case of using userSearch, and we alway expose this
extend type LimitedUser {
workspaceDomainPolicyCompliant(workspaceId: String): Boolean
workspaceRole(workspaceId: String): String
# if workspaceId is undefined | null, just return undefined
# this can be implemented by the workspaceCore resolver too, to avoid frontend component duplication
}
Expand Down
11 changes: 11 additions & 0 deletions packages/server/modules/core/graph/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ export type LimitedUser = {
totalOwnedStreamsFavorites: Scalars['Int']['output'];
verified?: Maybe<Scalars['Boolean']['output']>;
workspaceDomainPolicyCompliant?: Maybe<Scalars['Boolean']['output']>;
workspaceRole?: Maybe<Scalars['String']['output']>;
};


Expand Down Expand Up @@ -1136,6 +1137,15 @@ export type LimitedUserWorkspaceDomainPolicyCompliantArgs = {
workspaceId?: InputMaybe<Scalars['String']['input']>;
};


/**
* Limited user type, for showing public info about a user
* to another user
*/
export type LimitedUserWorkspaceRoleArgs = {
workspaceId?: InputMaybe<Scalars['String']['input']>;
};

/** Workspace metadata visible to non-workspace members. */
export type LimitedWorkspace = {
__typename?: 'LimitedWorkspace';
Expand Down Expand Up @@ -5775,6 +5785,7 @@ export type LimitedUserResolvers<ContextType = GraphQLContext, ParentType extend
totalOwnedStreamsFavorites?: Resolver<ResolversTypes['Int'], ParentType, ContextType>;
verified?: Resolver<Maybe<ResolversTypes['Boolean']>, ParentType, ContextType>;
workspaceDomainPolicyCompliant?: Resolver<Maybe<ResolversTypes['Boolean']>, ParentType, ContextType, Partial<LimitedUserWorkspaceDomainPolicyCompliantArgs>>;
workspaceRole?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType, Partial<LimitedUserWorkspaceRoleArgs>>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ export type LimitedUser = {
totalOwnedStreamsFavorites: Scalars['Int']['output'];
verified?: Maybe<Scalars['Boolean']['output']>;
workspaceDomainPolicyCompliant?: Maybe<Scalars['Boolean']['output']>;
workspaceRole?: Maybe<Scalars['String']['output']>;
};


Expand Down Expand Up @@ -1117,6 +1118,15 @@ export type LimitedUserWorkspaceDomainPolicyCompliantArgs = {
workspaceId?: InputMaybe<Scalars['String']['input']>;
};


/**
* Limited user type, for showing public info about a user
* to another user
*/
export type LimitedUserWorkspaceRoleArgs = {
workspaceId?: InputMaybe<Scalars['String']['input']>;
};

/** Workspace metadata visible to non-workspace members. */
export type LimitedWorkspace = {
__typename?: 'LimitedWorkspace';
Expand Down
18 changes: 18 additions & 0 deletions packages/server/modules/workspaces/graph/resolvers/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,24 @@ export = FF_WORKSPACES_MODULE_ENABLED
findEmailsByUserId: findEmailsByUserIdFactory({ db }),
getWorkspaceWithDomains: getWorkspaceWithDomainsFactory({ db })
})({ workspaceId, userId })
},
workspaceRole: async (parent, args, context) => {
const workspaceId = args.workspaceId
if (!workspaceId) return null

await authorizeResolver(
context.userId,
workspaceId,
Roles.Workspace.Member,
context.resourceAccessRules
)

const userId = parent.id

return await getWorkspaceRoleForUserFactory({ db })({
userId,
workspaceId
})
}
},
ServerInfo: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export = !FF_WORKSPACES_MODULE_ENABLED
}
},
LimitedUser: {
workspaceDomainPolicyCompliant: async () => null
workspaceDomainPolicyCompliant: async () => null,
workspaceRole: async () => null
},
ServerInfo: {
workspaces: () => ({})
Expand Down
10 changes: 10 additions & 0 deletions packages/server/test/graphql/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ export type LimitedUser = {
totalOwnedStreamsFavorites: Scalars['Int']['output'];
verified?: Maybe<Scalars['Boolean']['output']>;
workspaceDomainPolicyCompliant?: Maybe<Scalars['Boolean']['output']>;
workspaceRole?: Maybe<Scalars['String']['output']>;
};


Expand Down Expand Up @@ -1118,6 +1119,15 @@ export type LimitedUserWorkspaceDomainPolicyCompliantArgs = {
workspaceId?: InputMaybe<Scalars['String']['input']>;
};


/**
* Limited user type, for showing public info about a user
* to another user
*/
export type LimitedUserWorkspaceRoleArgs = {
workspaceId?: InputMaybe<Scalars['String']['input']>;
};

/** Workspace metadata visible to non-workspace members. */
export type LimitedWorkspace = {
__typename?: 'LimitedWorkspace';
Expand Down

0 comments on commit a784a72

Please sign in to comment.