修复项目无法删除问题
This commit is contained in:
@@ -86,7 +86,9 @@ func (s *Server) authorizeProject(ctx context.Context, projectID string) error {
|
||||
}
|
||||
var count int64
|
||||
if err := s.db.WithContext(ctx).Model(&model.UserProject{}).
|
||||
Where("user_id = ? AND project_id = ?", user.ID, projectID).Count(&count).Error; err != nil {
|
||||
Joins("JOIN projects ON projects.id = user_projects.project_id").
|
||||
Where("user_projects.user_id = ? AND user_projects.project_id = ? AND projects.archived_at IS NULL", user.ID, projectID).
|
||||
Count(&count).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if count == 0 {
|
||||
@@ -219,7 +221,8 @@ func userView(user model.User) map[string]any {
|
||||
|
||||
func (s *Server) projectsForUser(ctx context.Context, user model.User) ([]model.Project, error) {
|
||||
var projects []model.Project
|
||||
query := s.db.WithContext(ctx).Model(&model.Project{}).Order("name ASC")
|
||||
query := s.db.WithContext(ctx).Model(&model.Project{}).
|
||||
Where("projects.archived_at IS NULL").Order("projects.name ASC")
|
||||
if user.Role != model.RoleAdmin {
|
||||
query = query.Joins("JOIN user_projects ON user_projects.project_id = projects.id").
|
||||
Where("user_projects.user_id = ?", user.ID)
|
||||
|
||||
Reference in New Issue
Block a user