diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-09-09 05:09:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-08 21:09:23 +0000 |
commit | e3ed67859a434f2fef1db175e9c82251a7f9f6c9 (patch) | |
tree | e4c48b0c17d6d5a9507c3fc1479d7da2faba59dd /models/org_team.go | |
parent | b8ad558c93052ee3e2f43f1e24e6f5c134da36c4 (diff) | |
download | gitea-e3ed67859a434f2fef1db175e9c82251a7f9f6c9.tar.gz gitea-e3ed67859a434f2fef1db175e9c82251a7f9f6c9.zip |
Move some functions to service layer (#26969)
Diffstat (limited to 'models/org_team.go')
-rw-r--r-- | models/org_team.go | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/models/org_team.go b/models/org_team.go index f887c9ee98..cf3680990d 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -485,12 +485,12 @@ func removeTeamMember(ctx context.Context, team *organization.Team, userID int64 } // Remove watches from now unaccessible - if err := reconsiderWatches(ctx, repo, userID); err != nil { + if err := ReconsiderWatches(ctx, repo, userID); err != nil { return err } // Remove issue assignments from now unaccessible - if err := reconsiderRepoIssuesAssignee(ctx, repo, userID); err != nil { + if err := ReconsiderRepoIssuesAssignee(ctx, repo, userID); err != nil { return err } } @@ -523,3 +523,33 @@ func RemoveTeamMember(team *organization.Team, userID int64) error { } return committer.Commit() } + +func ReconsiderRepoIssuesAssignee(ctx context.Context, repo *repo_model.Repository, uid int64) error { + user, err := user_model.GetUserByID(ctx, uid) + if err != nil { + return err + } + + if canAssigned, err := access_model.CanBeAssigned(ctx, user, repo, true); err != nil || canAssigned { + return err + } + + if _, err := db.GetEngine(ctx).Where(builder.Eq{"assignee_id": uid}). + In("issue_id", builder.Select("id").From("issue").Where(builder.Eq{"repo_id": repo.ID})). + Delete(&issues_model.IssueAssignees{}); err != nil { + return fmt.Errorf("Could not delete assignee[%d] %w", uid, err) + } + return nil +} + +func ReconsiderWatches(ctx context.Context, repo *repo_model.Repository, uid int64) error { + if has, err := access_model.HasAccess(ctx, uid, repo); err != nil || has { + return err + } + if err := repo_model.WatchRepo(ctx, uid, repo.ID, false); err != nil { + return err + } + + // Remove all IssueWatches a user has subscribed to in the repository + return issues_model.RemoveIssueWatchersByRepoID(ctx, uid, repo.ID) +} |