diff --git a/sqle/model/project_permission.go b/sqle/model/project_permission.go index 689cc18c8e..b9e040606f 100644 --- a/sqle/model/project_permission.go +++ b/sqle/model/project_permission.go @@ -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 { @@ -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 { @@ -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) } /* diff --git a/sqle/model/user.go b/sqle/model/user.go index 1f654123fc..e5c9cefc3f 100644 --- a/sqle/model/user.go +++ b/sqle/model/user.go @@ -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) +}