Skip to content

Commit

Permalink
chore:When there is no matching user, the person to be operated is al…
Browse files Browse the repository at this point in the history
…l administrators of the project
  • Loading branch information
taolx0 committed Jan 8, 2024
1 parent 805c04f commit 210b56a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sqle/model/project_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ AND (w.create_user_id = ? OR cur_ass_user.id = ? OR op_ass_user.id = ?)
return count > 0, nil
}

// GetCanAuditWorkflowUsers will return admin user if no qualified user is found, preventing the process from being stuck because no user can operate
// GetCanAuditWorkflowUsers will return supper admin and project admin user if no qualified user is found, preventing the process from being stuck because no user can operate
func (s *Storage) GetCanAuditWorkflowUsers(instance *Instance) (users []*User, err error) {
users, err = s.GetWithOperationUserFromInstance(instance, OP_WORKFLOW_AUDIT)
if err != nil {
Expand All @@ -333,10 +333,10 @@ func (s *Storage) GetCanAuditWorkflowUsers(instance *Instance) (users []*User, e
if len(users) != 0 {
return
}
return s.GetUsersByNames([]string{DefaultAdminUser})
return s.GetManageUsersByProjectID(instance.ProjectId)
}

// GetCanExecuteWorkflowUsers will return admin user if no qualified user is found, preventing the process from being stuck because no user can operate
// GetCanExecuteWorkflowUsers will return supper admin and project admin if no qualified user is found, preventing the process from being stuck because no user can operate
func (s *Storage) GetCanExecuteWorkflowUsers(instance *Instance) (users []*User, err error) {
users, err = s.GetWithOperationUserFromInstance(instance, OP_WORKFLOW_EXECUTE)
if err != nil {
Expand All @@ -345,7 +345,7 @@ func (s *Storage) GetCanExecuteWorkflowUsers(instance *Instance) (users []*User,
if len(users) != 0 {
return
}
return s.GetUsersByNames([]string{DefaultAdminUser})
return s.GetManageUsersByProjectID(instance.ProjectId)
}

/*
Expand Down
10 changes: 10 additions & 0 deletions sqle/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,13 @@ func (s *Storage) GetMemberTips(projectName string) ([]*User, error) {
Find(&users).Error
return users, errors.ConnectStorageErrWrapper(err)
}

func (s *Storage) GetManageUsersByProjectID(projectID uint) ([]*User, error) {
var users []*User
err := s.db.Model(&User{}).
Joins("LEFT JOIN project_manager pm ON pm.user_id = users.id").
Where("pm.project_id = ?", projectID).
Where("users.deleted_at IS NULL").
Find(&users).Error
return users, errors.ConnectStorageErrWrapper(err)
}

0 comments on commit 210b56a

Please sign in to comment.