mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
* Add admin role to GroupUser This change adds an admin role to GroupUser that allows group admins to: 1. Administer other users in the group 2. Change the group name Changes include: - Database migration to add isAdmin field to group_users table - Updated GroupUser model to include isAdmin field - Added isGroupAdmin policy utility function - Updated group policy to allow group admins to update groups - Added API endpoints for managing admin status - Updated GroupUsersStore to handle admin functionality - Added tests for the new functionality * Replace isAdmin with role-based approach for GroupUser - Added role field to GroupUser model using UserRole.Admin and UserRole.Member - Created migration to convert isAdmin boolean to role enum - Updated policies to be synchronous and require pre-loaded relationships - Updated API endpoints to support both role and legacy isAdmin parameters - Updated GroupUsersStore to handle role-based functionality - Updated tests to use role instead of isAdmin - Maintained backward compatibility with isAdmin in presenters * Remove isAdmin logic from GroupUser implementation - Removed isAdmin parameter from GroupUsersStore methods - Removed isAdmin field from presenter output - Removed isAdmin from API schemas - Removed isAdmin parameter handling in API endpoints - Updated tests to use role instead of isAdmin - Simplified role handling throughout the codebase * lint * tests * role -> permission * fe * test * Change permission label from 'Admin' to 'Manage' --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
118 lines
3.1 KiB
TypeScript
118 lines
3.1 KiB
TypeScript
import { z } from "zod";
|
|
import { GroupPermission } from "@shared/types";
|
|
import { Group } from "@server/models";
|
|
|
|
const BaseIdSchema = z.object({
|
|
/** Group Id */
|
|
id: z.string().uuid(),
|
|
});
|
|
|
|
export const GroupsListSchema = z.object({
|
|
body: z.object({
|
|
/** Groups sorting direction */
|
|
direction: z
|
|
.string()
|
|
.optional()
|
|
.transform((val) => (val !== "ASC" ? "DESC" : val)),
|
|
/** Groups sorting column */
|
|
sort: z
|
|
.string()
|
|
.refine((val) => Object.keys(Group.getAttributes()).includes(val), {
|
|
message: "Invalid sort parameter",
|
|
})
|
|
.default("updatedAt"),
|
|
/** Only list groups where this user is a member */
|
|
userId: z.string().uuid().optional(),
|
|
/** Find group matching externalId */
|
|
externalId: z.string().optional(),
|
|
/** @deprecated Find group with matching name */
|
|
name: z.string().optional(),
|
|
/** Find group matching query */
|
|
query: z.string().optional(),
|
|
}),
|
|
});
|
|
|
|
export type GroupsListReq = z.infer<typeof GroupsListSchema>;
|
|
|
|
export const GroupsInfoSchema = z.object({
|
|
body: z.object({
|
|
/** Group Id */
|
|
id: z.string().uuid().optional(),
|
|
/** External source. */
|
|
externalId: z.string().optional(),
|
|
}),
|
|
});
|
|
|
|
export type GroupsInfoReq = z.infer<typeof GroupsInfoSchema>;
|
|
|
|
export const GroupsCreateSchema = z.object({
|
|
body: z.object({
|
|
/** Group name */
|
|
name: z.string(),
|
|
/** Optionally link this group to an external source. */
|
|
externalId: z.string().optional(),
|
|
}),
|
|
});
|
|
|
|
export type GroupsCreateReq = z.infer<typeof GroupsCreateSchema>;
|
|
|
|
export const GroupsUpdateSchema = z.object({
|
|
body: BaseIdSchema.extend({
|
|
/** Group name */
|
|
name: z.string().optional(),
|
|
/** Optionally link this group to an external source. */
|
|
externalId: z.string().optional(),
|
|
}),
|
|
});
|
|
|
|
export type GroupsUpdateReq = z.infer<typeof GroupsUpdateSchema>;
|
|
|
|
export const GroupsDeleteSchema = z.object({
|
|
body: BaseIdSchema,
|
|
});
|
|
|
|
export type GroupsDeleteReq = z.infer<typeof GroupsDeleteSchema>;
|
|
|
|
export const GroupsMembershipsSchema = z.object({
|
|
body: BaseIdSchema.extend({
|
|
/** Group name search query */
|
|
query: z.string().optional(),
|
|
}),
|
|
});
|
|
|
|
export type GroupsMembershipsReq = z.infer<typeof GroupsMembershipsSchema>;
|
|
|
|
export const GroupsAddUserSchema = z.object({
|
|
body: BaseIdSchema.extend({
|
|
/** User Id */
|
|
userId: z.string().uuid(),
|
|
/** The permission of the user in the group */
|
|
permission: z
|
|
.nativeEnum(GroupPermission)
|
|
.optional()
|
|
.default(GroupPermission.Member),
|
|
}),
|
|
});
|
|
|
|
export type GroupsAddUserReq = z.infer<typeof GroupsAddUserSchema>;
|
|
|
|
export const GroupsRemoveUserSchema = z.object({
|
|
body: BaseIdSchema.extend({
|
|
/** User Id */
|
|
userId: z.string().uuid(),
|
|
}),
|
|
});
|
|
|
|
export type GroupsRemoveUserReq = z.infer<typeof GroupsRemoveUserSchema>;
|
|
|
|
export const GroupsUpdateUserSchema = z.object({
|
|
body: BaseIdSchema.extend({
|
|
/** User Id */
|
|
userId: z.string().uuid(),
|
|
/** The permission of the user in the group */
|
|
permission: z.nativeEnum(GroupPermission),
|
|
}),
|
|
});
|
|
|
|
export type GroupsUpdateUserReq = z.infer<typeof GroupsUpdateUserSchema>;
|