Changes
1 changed files (+26/-26)
-
-
@@ -23,30 +23,30 @@ "pocka.jp/x/yamori/backend/core/projection"workspaceEvent "pocka.jp/x/yamori/backend/events/workspace" ) func createUserSystemError(message string) (*connect.Response[workspaceV2.CreateUserResponse], error) { func createUserSystemError(message string) *connect.Response[workspaceV2.CreateUserResponse] { return connect.NewResponse(&workspaceV2.CreateUserResponse{ Result: &workspaceV2.CreateUserResponse_SystemError{ SystemError: &errorV1.SystemError{ Message: proto.String(message), }, }, }), nil }) } func createUserAuthError() (*connect.Response[workspaceV2.CreateUserResponse], error) { func createUserAuthError() *connect.Response[workspaceV2.CreateUserResponse] { return connect.NewResponse(&workspaceV2.CreateUserResponse{ Result: &workspaceV2.CreateUserResponse_AuthenticationError{ AuthenticationError: &errorV1.AuthenticationError{}, }, }), nil }) } func createUserPermError() (*connect.Response[workspaceV2.CreateUserResponse], error) { func createUserPermError() *connect.Response[workspaceV2.CreateUserResponse] { return connect.NewResponse(&workspaceV2.CreateUserResponse{ Result: &workspaceV2.CreateUserResponse_PermissionError{ PermissionError: &errorV1.PermissionError{}, }, }), nil }) } func (s *Service) CreateUser(
-
@@ -61,31 +61,31 @@header := req.Header() token, err := s.core.LoadTokenFromCookie(&header) if err != nil || token == nil { return createUserAuthError() return createUserAuthError(), nil } tx, err := s.core.DB.Begin() if err != nil { logger.Error("Failed to begin transaction", "error", err) return createUserSystemError("Database error") return createUserSystemError("Database error"), nil } defer tx.Rollback() users, err := projection.GetUsers(tx) if err != nil { logger.Error("Failed to read users projection", "error", err) return createUserSystemError("Database error") return createUserSystemError("Database error"), nil } secret, err := projection.GetLoginJwtSecret(tx) if err != nil { logger.Error("Failed to read login_jwt_secret projection", "error", err) return createUserSystemError("Database error") return createUserSystemError("Database error"), nil } if err := event.UpdateProjections(tx, users, secret); err != nil { logger.Error("Failed to update projections", "error", err) return createUserSystemError("Database error") return createUserSystemError("Database error"), nil } user, err := token.FindUser(secret, users)
-
@@ -148,7 +148,7 @@ requiredPerm = types.Permission_PERMISSION_ADD_ADMIN_USER} if !slices.Contains(user.Permissions, requiredPerm) { return createUserPermError() return createUserPermError(), nil } for _, u := range users.Projection.Users {
-
@@ -164,7 +164,7 @@id, err := uuid.NewRandom() if err != nil { logger.Error("Failed to generate UUID", "error", err) return createUserSystemError("Unable to issue a new ID") return createUserSystemError("Unable to issue a new ID"), nil } keyID := make([]byte, 32)
-
@@ -176,7 +176,7 @@ workspaceEvent.ConfigurePasswordLogin(id.String(), password),}) if err != nil { logger.Error("Failed to append user creation events", "error", err) return createUserSystemError("Database error") return createUserSystemError("Database error"), nil } if req.Msg.GetIsAdmin() {
-
@@ -185,7 +185,7 @@ workspaceEvent.GrantAdminAccess(id.String()),}) if err != nil { logger.Error("Failed to append adming grant events", "error", err) return createUserSystemError("Database error") return createUserSystemError("Database error"), nil } } else { permissions := make([]types.Permission, 0, 32)
-
@@ -198,7 +198,7 @@ }if req.Msg.Permissions.GetCanDeleteRegularUser() { if !slices.Contains(user.Permissions, types.Permission_PERMISSION_DELETE_REGULAR_USER) { return createUserPermError() return createUserPermError(), nil } permissions = append(permissions, types.Permission_PERMISSION_DELETE_REGULAR_USER)
-
@@ -206,11 +206,11 @@ }if req.Msg.Permissions.GetCanReadOtherUserProfile() { if !slices.Contains(user.Permissions, types.Permission_PERMISSION_READ_REGULAR_USER_PROFILE) { return createUserPermError() return createUserPermError(), nil } if !slices.Contains(user.Permissions, types.Permission_PERMISSION_READ_ADMIN_USER_PROFILE) { return createUserPermError() return createUserPermError(), nil } permissions = append(
-
@@ -222,7 +222,7 @@ }if req.Msg.Permissions.GetCanUpdateOtherRegularUserProfile() { if !slices.Contains(user.Permissions, types.Permission_PERMISSION_UPDATE_REGULAR_USER_PROFILE) { return createUserPermError() return createUserPermError(), nil } permissions = append(permissions, types.Permission_PERMISSION_UPDATE_REGULAR_USER_PROFILE)
-
@@ -230,7 +230,7 @@ }if req.Msg.Permissions.GetCanUpdateSelfProfile() { if !slices.Contains(user.Permissions, types.Permission_PERMISSION_UPDATE_SELF_PROFILE) { return createUserPermError() return createUserPermError(), nil } permissions = append(permissions, types.Permission_PERMISSION_UPDATE_SELF_PROFILE)
-
@@ -238,7 +238,7 @@ }if req.Msg.Permissions.GetCanUpdateOtherRegularUserLoginMethod() { if !slices.Contains(user.Permissions, types.Permission_PERMISSION_UPDATE_REGULAR_USER_LOGIN_METHOD) { return createUserPermError() return createUserPermError(), nil } permissions = append(
-
@@ -249,7 +249,7 @@ }if req.Msg.Permissions.GetCanUpdateWorkspace() { if !slices.Contains(user.Permissions, types.Permission_PERMISSION_EDIT_WORKSPACE_PROFILE) { return createUserPermError() return createUserPermError(), nil } permissions = append(permissions, types.Permission_PERMISSION_EDIT_WORKSPACE_PROFILE)
-
@@ -261,18 +261,18 @@ workspaceEvent.GrantPermission(id.String(), permissions),}) if err != nil { logger.Error("Failed to append a permissions grant event", "error", err) return createUserSystemError("Database error") return createUserSystemError("Database error"), nil } } if err := event.UpdateProjections(tx, users); err != nil { logger.Error("Failed to update users projection", "error", err) return createUserSystemError("Database error") return createUserSystemError("Database error"), nil } if err := tx.Commit(); err != nil { logger.Error("Failed to commit transaction", "error", err) return createUserSystemError("Database error") return createUserSystemError("Database error"), nil } for _, u := range users.Projection.Users {
-
@@ -293,5 +293,5 @@ "id",id.String(), ) return createUserSystemError("Database error") return createUserSystemError("Database error"), nil }
-