diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-09-08 12:51:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-08 04:51:15 +0000 |
commit | 4f32abaf941ba30ade1f96930a05d14f1c6a6782 (patch) | |
tree | 9351b7d654b20db032867041b0292924ec93bb3f /models/org_team.go | |
parent | 3c0c27965836328abd2668dcd77710ee2460535e (diff) | |
download | gitea-4f32abaf941ba30ade1f96930a05d14f1c6a6782.tar.gz gitea-4f32abaf941ba30ade1f96930a05d14f1c6a6782.zip |
move repository deletion to service layer (#26948)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'models/org_team.go')
-rw-r--r-- | models/org_team.go | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/models/org_team.go b/models/org_team.go index be0c859a4b..f887c9ee98 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -151,85 +151,6 @@ func removeAllRepositories(ctx context.Context, t *organization.Team) (err error return nil } -// HasRepository returns true if given repository belong to team. -func HasRepository(t *organization.Team, repoID int64) bool { - return organization.HasTeamRepo(db.DefaultContext, t.OrgID, t.ID, repoID) -} - -// removeRepository removes a repository from a team and recalculates access -// Note: Repository shall not be removed from team if it includes all repositories (unless the repository is deleted) -func removeRepository(ctx context.Context, t *organization.Team, repo *repo_model.Repository, recalculate bool) (err error) { - e := db.GetEngine(ctx) - if err = organization.RemoveTeamRepo(ctx, t.ID, repo.ID); err != nil { - return err - } - - t.NumRepos-- - if _, err = e.ID(t.ID).Cols("num_repos").Update(t); err != nil { - return err - } - - // Don't need to recalculate when delete a repository from organization. - if recalculate { - if err = access_model.RecalculateTeamAccesses(ctx, repo, t.ID); err != nil { - return err - } - } - - teamUsers, err := organization.GetTeamUsersByTeamID(ctx, t.ID) - if err != nil { - return fmt.Errorf("getTeamUsersByTeamID: %w", err) - } - for _, teamUser := range teamUsers { - has, err := access_model.HasAccess(ctx, teamUser.UID, repo) - if err != nil { - return err - } else if has { - continue - } - - if err = repo_model.WatchRepo(ctx, teamUser.UID, repo.ID, false); err != nil { - return err - } - - // Remove all IssueWatches a user has subscribed to in the repositories - if err := issues_model.RemoveIssueWatchersByRepoID(ctx, teamUser.UID, repo.ID); err != nil { - return err - } - } - - return nil -} - -// RemoveRepository removes repository from team of organization. -// If the team shall include all repositories the request is ignored. -func RemoveRepository(t *organization.Team, repoID int64) error { - if !HasRepository(t, repoID) { - return nil - } - - if t.IncludesAllRepositories { - return nil - } - - repo, err := repo_model.GetRepositoryByID(db.DefaultContext, repoID) - if err != nil { - return err - } - - ctx, committer, err := db.TxContext(db.DefaultContext) - if err != nil { - return err - } - defer committer.Close() - - if err = removeRepository(ctx, t, repo, true); err != nil { - return err - } - - return committer.Commit() -} - // NewTeam creates a record of new team. // It's caller's responsibility to assign organization ID. func NewTeam(t *organization.Team) (err error) { |