diff --git a/controller/permissions.go b/controller/permissions.go index 316b3c1..034df38 100644 --- a/controller/permissions.go +++ b/controller/permissions.go @@ -20,17 +20,13 @@ func NewPermissions(permissionsService permissionsService) Permissions { } } -// GetProfile +// GetPermissions // @Tags user -// @Summary Получить профиль -// @Description Получить данные профиля +// @Summary Получить все разрашения +// @Description Получить все разрашения // @Accept json // @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Success 200 {object} domain.AdminUserShort -// @Failure 400 {object} domain.GrpcError "Невалидный токен" -// @Failure 404 {object} domain.GrpcError "Пользователя не существует" -// @Failure 500 {object} domain.GrpcError +// @Success 200 {array} domain.Permission // @Router /user/get_profile [POST] func (u Permissions) GetPermissions(ctx context.Context) []domain.Permission { return u.permissionsService.All(ctx) diff --git a/controller/role.go b/controller/role.go index 6ec6008..7772e06 100644 --- a/controller/role.go +++ b/controller/role.go @@ -28,70 +28,68 @@ func NewRole(roleService roleService) Role { } // All -// @Tags user -// @Summary Список пользователей -// @Description Получить список пользователей +// @Tags role +// @Summary Список ролей +// @Description Получить список ролей // @Accept json // @Produce json // @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.UsersRequest true "Тело запроса" -// @Success 200 {object} domain.UsersResponse +// @Success 200 {array} domain.Role // @Failure 400 {object} domain.GrpcError // @Failure 500 {object} domain.GrpcError -// @Router /user/get_users [POST] +// @Router /role/all [POST] func (u Role) All(ctx context.Context) ([]domain.Role, error) { users, err := u.roleService.All(ctx) if err != nil { - return nil, errors.WithMessage(err, "get users") + return nil, errors.WithMessage(err, "get roles") } return users, nil } -// CreateUser +// CreateRole // @Tags user -// @Summary Создать пользователя -// @Description Создать пользователя +// @Summary Создать роль +// @Description Создать роль // @Accept json // @Produce json // @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.CreateUserRequest true "Тело запроса" +// @Param body body domain.CreateRoleRequest true "Тело запроса" // @Success 200 {object} domain.User // @Failure 400 {object} domain.GrpcError "Невалидное тело запроса" -// @Failure 409 {object} domain.GrpcError "Пользователь с указанным email уже существует" +// @Failure 409 {object} domain.GrpcError "Роль с указанным именем уже существует" // @Failure 500 {object} domain.GrpcError -// @Router /user/create_user [POST] +// @Router /role/create [POST] func (u Role) CreateRole(ctx context.Context, authData grpc.AuthData, req domain.CreateRoleRequest) (*domain.Role, error) { adminId, err := getUserToken(authData) if err != nil { return nil, err } - user, err := u.roleService.Create(ctx, req, adminId) + role, err := u.roleService.Create(ctx, req, adminId) switch { case errors.Is(err, domain.ErrAlreadyExists): - return nil, status.Error(codes.AlreadyExists, "role with the same user-role pair") + return nil, status.Error(codes.AlreadyExists, "role with current name already exists") case err != nil: return nil, errors.WithMessage(err, "create role") default: - return user, nil + return role, nil } } -// UpdateUser -// @Tags user -// @Summary Обновить пользователя -// @Description Обновить данные существующего пользователя +// UpdateRole +// @Tags role +// @Summary Обновить роль +// @Description Обновить данные существующую роль // @Accept json // @Produce json // @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.UpdateUserRequest true "Тело запроса" -// @Success 200 {object} domain.User -// @Failure 400 {object} domain.GrpcError "Невалидное тело запроса" -// @Failure 404 {object} domain.GrpcError "Пользователь с указанным id не существует" -// @Failure 409 {object} domain.GrpcError "Пользователь с указанным email уже существует" +// @Param body body domain.UpdateRoleRequest true "Тело запроса" +// @Success 200 {object} domain.Role +// @Failure 404 {object} domain.GrpcError "Роль с указанным id не существует" +// @Failure 409 {object} domain.GrpcError "Роль с указанным именем уже существует" // @Failure 500 {object} domain.GrpcError -// @Router /user/update_user [POST] +// @Router /role/update [POST] func (u Role) UpdateRole(ctx context.Context, authData grpc.AuthData, req domain.UpdateRoleRequest) (*domain.Role, error) { adminId, err := getUserToken(authData) if err != nil { @@ -101,30 +99,28 @@ func (u Role) UpdateRole(ctx context.Context, authData grpc.AuthData, req domain result, err := u.roleService.Update(ctx, req, adminId) switch { case errors.Is(err, domain.ErrNotFound): - return nil, status.Error(codes.NotFound, "user not found") - case errors.Is(err, domain.ErrInvalid): - return nil, status.Error(codes.InvalidArgument, "user modification is not available") + return nil, status.Error(codes.NotFound, "role not found") case errors.Is(err, domain.ErrAlreadyExists): - return nil, status.Error(codes.AlreadyExists, "user with the same email already exists") + return nil, status.Error(codes.AlreadyExists, "role with current name already exists") case err != nil: - return nil, errors.WithMessage(err, "update user") + return nil, errors.WithMessage(err, "update role") default: return result, nil } } -// DeleteUser -// @Tags user -// @Summary Удалить пользователя -// @Description Удалить существующего пользователя +// DeleteRole +// @Tags role +// @Summary Удалить роль +// @Description Удалить существующую роль // @Accept json // @Produce json // @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.IdentitiesRequest true "Тело запроса" -// @Success 200 {object} domain.DeleteResponse +// @Param body body domain.DeleteRoleRequest true "Тело запроса" +// @Success 200 // @Failure 400 {object} domain.GrpcError "Невалидное тело запроса" // @Failure 500 {object} domain.GrpcError -// @Router /user/delete_user [POST] +// @Router /role/delete [POST] func (u Role) DeleteRole(ctx context.Context, authData grpc.AuthData, req domain.DeleteRoleRequest) error { adminId, err := getUserToken(authData) if err != nil { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index a0f0ee6..8e21ad2 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -15,8 +15,16 @@ definitions: type: string lastName: type: string + permissions: + items: + type: string + type: array role: type: string + roles: + items: + type: integer + type: array required: - email type: object @@ -40,8 +48,23 @@ definitions: totalCount: type: integer type: object + domain.CreateRoleRequest: + properties: + changeMessage: + type: string + externalGroup: + type: string + name: + type: string + permissions: + items: + type: string + type: array + type: object domain.CreateUserRequest: properties: + description: + type: string email: type: string firstName: @@ -50,8 +73,10 @@ definitions: type: string password: type: string - roleId: - type: integer + roles: + items: + type: integer + type: array required: - email - password @@ -61,6 +86,11 @@ definitions: deleted: type: integer type: object + domain.DeleteRoleRequest: + properties: + id: + type: integer + type: object domain.GrpcError: properties: details: @@ -123,6 +153,13 @@ definitions: required: - limit type: object + domain.Permission: + properties: + key: + type: string + name: + type: string + type: object domain.RevokeRequest: properties: id: @@ -132,14 +169,20 @@ definitions: type: object domain.Role: properties: + changeMessage: + type: string createdAt: type: string - description: + externalGroup: type: string id: type: integer name: type: string + permissions: + items: + type: string + type: array updatedAt: type: string type: object @@ -164,8 +207,27 @@ definitions: offset: type: integer type: object + domain.UpdateRoleRequest: + properties: + changeMessage: + type: string + externalGroup: + type: string + id: + type: integer + name: + type: string + permissions: + items: + type: string + type: array + type: object domain.UpdateUserRequest: properties: + blocked: + type: boolean + description: + type: string email: type: string firstName: @@ -174,10 +236,10 @@ definitions: type: integer lastName: type: string - password: - type: string - roleId: - type: integer + roles: + items: + type: integer + type: array required: - id type: object @@ -187,6 +249,8 @@ definitions: type: boolean createdAt: type: string + description: + type: string email: type: string firstName: @@ -195,10 +259,12 @@ definitions: type: integer lastName: type: string - roleId: - type: integer - roleName: + lastSessionCreatedAt: type: string + roles: + items: + type: integer + type: array updatedAt: type: string type: object @@ -360,6 +426,148 @@ paths: summary: Получение списка логов tags: - log + /role/all: + post: + consumes: + - application/json + description: Получить список ролей + parameters: + - description: Токен администратора + in: header + name: X-AUTH-ADMIN + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/domain.Role' + type: array + "400": + description: Bad Request + schema: + $ref: '#/definitions/domain.GrpcError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/domain.GrpcError' + summary: Список ролей + tags: + - role + /role/create: + post: + consumes: + - application/json + description: Создать роль + parameters: + - description: Токен администратора + in: header + name: X-AUTH-ADMIN + required: true + type: string + - description: Тело запроса + in: body + name: body + required: true + schema: + $ref: '#/definitions/domain.CreateRoleRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/domain.User' + "400": + description: Невалидное тело запроса + schema: + $ref: '#/definitions/domain.GrpcError' + "409": + description: Роль с указанным именем уже существует + schema: + $ref: '#/definitions/domain.GrpcError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/domain.GrpcError' + summary: Создать роль + tags: + - user + /role/delete: + post: + consumes: + - application/json + description: Удалить существующую роль + parameters: + - description: Токен администратора + in: header + name: X-AUTH-ADMIN + required: true + type: string + - description: Тело запроса + in: body + name: body + required: true + schema: + $ref: '#/definitions/domain.DeleteRoleRequest' + produces: + - application/json + responses: + "200": + description: "" + "400": + description: Невалидное тело запроса + schema: + $ref: '#/definitions/domain.GrpcError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/domain.GrpcError' + summary: Удалить роль + tags: + - role + /role/update: + post: + consumes: + - application/json + description: Обновить данные существующую роль + parameters: + - description: Токен администратора + in: header + name: X-AUTH-ADMIN + required: true + type: string + - description: Тело запроса + in: body + name: body + required: true + schema: + $ref: '#/definitions/domain.UpdateRoleRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/domain.Role' + "404": + description: Роль с указанным id не существует + schema: + $ref: '#/definitions/domain.GrpcError' + "409": + description: Роль с указанным именем уже существует + schema: + $ref: '#/definitions/domain.GrpcError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/domain.GrpcError' + summary: Обновить роль + tags: + - role /secure/authenticate: post: consumes: @@ -654,36 +862,6 @@ paths: summary: Получить профиль tags: - user - /user/get_roles: - post: - consumes: - - application/json - parameters: - - description: Токен администратора - in: header - name: X-AUTH-ADMIN - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/domain.Role' - type: array - "400": - description: Bad Request - schema: - $ref: '#/definitions/domain.GrpcError' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/domain.GrpcError' - summary: Список доступных ролей - tags: - - user /user/get_users: post: consumes: