aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository/collaboration.go
diff options
context:
space:
mode:
Diffstat (limited to 'services/repository/collaboration.go')
-rw-r--r--services/repository/collaboration.go32
1 files changed, 29 insertions, 3 deletions
diff --git a/services/repository/collaboration.go b/services/repository/collaboration.go
index abe0489fc5..b5fc523623 100644
--- a/services/repository/collaboration.go
+++ b/services/repository/collaboration.go
@@ -6,9 +6,10 @@ package repository
import (
"context"
+ "fmt"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/perm"
access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
@@ -94,14 +95,39 @@ func DeleteCollaboration(ctx context.Context, repo *repo_model.Repository, colla
return err
}
- if err = models.ReconsiderWatches(ctx, repo, collaborator); err != nil {
+ if err = ReconsiderWatches(ctx, repo, collaborator); err != nil {
return err
}
// Unassign a user from any issue (s)he has been assigned to in the repository
- if err := models.ReconsiderRepoIssuesAssignee(ctx, repo, collaborator); err != nil {
+ if err := ReconsiderRepoIssuesAssignee(ctx, repo, collaborator); err != nil {
return err
}
return committer.Commit()
}
+
+func ReconsiderRepoIssuesAssignee(ctx context.Context, repo *repo_model.Repository, user *user_model.User) error {
+ 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": user.ID}).
+ 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", user.ID, err)
+ }
+ return nil
+}
+
+func ReconsiderWatches(ctx context.Context, repo *repo_model.Repository, user *user_model.User) error {
+ if has, err := access_model.HasAnyUnitAccess(ctx, user.ID, repo); err != nil || has {
+ return err
+ }
+ if err := repo_model.WatchRepo(ctx, user, repo, false); err != nil {
+ return err
+ }
+
+ // Remove all IssueWatches a user has subscribed to in the repository
+ return issues_model.RemoveIssueWatchersByRepoID(ctx, user.ID, repo.ID)
+}