diff --git a/.deadcode-out b/.deadcode-out index 20ccfc6473..70a74128eb 100644 --- a/.deadcode-out +++ b/.deadcode-out @@ -22,11 +22,6 @@ code.gitea.io/gitea/models/actions ScheduleList.LoadTriggerUser ScheduleList.LoadRepos -code.gitea.io/gitea/models/asymkey - ErrGPGKeyAccessDenied.Error - ErrGPGKeyAccessDenied.Unwrap - HasDeployKey - code.gitea.io/gitea/models/auth GetSourceByName WebAuthnCredentials @@ -54,9 +49,7 @@ code.gitea.io/gitea/models/git code.gitea.io/gitea/models/issues IsErrUnknownDependencyType - ErrNewIssueInsert.Error IsErrIssueWasClosed - ChangeMilestoneStatus code.gitea.io/gitea/models/organization GetTeamNamesByID diff --git a/models/asymkey/error.go b/models/asymkey/error.go index 03bc82302f..e38ba121c6 100644 --- a/models/asymkey/error.go +++ b/models/asymkey/error.go @@ -192,28 +192,6 @@ func (err ErrGPGKeyIDAlreadyUsed) Unwrap() error { return util.ErrAlreadyExist } -// ErrGPGKeyAccessDenied represents a "GPGKeyAccessDenied" kind of Error. -type ErrGPGKeyAccessDenied struct { - UserID int64 - KeyID int64 -} - -// IsErrGPGKeyAccessDenied checks if an error is a ErrGPGKeyAccessDenied. -func IsErrGPGKeyAccessDenied(err error) bool { - _, ok := err.(ErrGPGKeyAccessDenied) - return ok -} - -// Error pretty-prints an error of type ErrGPGKeyAccessDenied. -func (err ErrGPGKeyAccessDenied) Error() string { - return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d]", - err.UserID, err.KeyID) -} - -func (err ErrGPGKeyAccessDenied) Unwrap() error { - return util.ErrPermissionDenied -} - // ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error. type ErrKeyAccessDenied struct { UserID int64 diff --git a/models/asymkey/ssh_key_deploy.go b/models/asymkey/ssh_key_deploy.go index 923c5020ed..429635330d 100644 --- a/models/asymkey/ssh_key_deploy.go +++ b/models/asymkey/ssh_key_deploy.go @@ -105,14 +105,6 @@ func addDeployKey(ctx context.Context, keyID, repoID int64, name, fingerprint st return key, db.Insert(ctx, key) } -// HasDeployKey returns true if public key is a deploy key of given repository. -func HasDeployKey(ctx context.Context, keyID, repoID int64) bool { - has, _ := db.GetEngine(ctx). - Where("key_id = ? AND repo_id = ?", keyID, repoID). - Get(new(DeployKey)) - return has -} - // AddDeployKey add new deploy key to database and authorized_keys file. func AddDeployKey(ctx context.Context, repoID int64, name, content string, readOnly bool) (*DeployKey, error) { fingerprint, err := CalcFingerprint(content) diff --git a/models/issues/issue.go b/models/issues/issue.go index 1e969790d7..6bd91797e7 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -63,21 +63,6 @@ func (err ErrIssueIsClosed) Error() string { return fmt.Sprintf("issue is closed [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index) } -// ErrNewIssueInsert is used when the INSERT statement in newIssue fails -type ErrNewIssueInsert struct { - OriginalError error -} - -// IsErrNewIssueInsert checks if an error is a ErrNewIssueInsert. -func IsErrNewIssueInsert(err error) bool { - _, ok := err.(ErrNewIssueInsert) - return ok -} - -func (err ErrNewIssueInsert) Error() string { - return err.OriginalError.Error() -} - // ErrIssueWasClosed is used when close a closed issue type ErrIssueWasClosed struct { ID int64 diff --git a/models/issues/issue_update.go b/models/issues/issue_update.go index 31c8bdc17b..775ebfadad 100644 --- a/models/issues/issue_update.go +++ b/models/issues/issue_update.go @@ -433,7 +433,7 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, la LabelIDs: labelIDs, Attachments: uuids, }); err != nil { - if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) || IsErrNewIssueInsert(err) { + if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) { return err } return fmt.Errorf("newIssue: %w", err) diff --git a/models/issues/milestone.go b/models/issues/milestone.go index 4b3cb0e858..03fab8b3ee 100644 --- a/models/issues/milestone.go +++ b/models/issues/milestone.go @@ -251,21 +251,6 @@ func ChangeMilestoneStatusByRepoIDAndID(ctx context.Context, repoID, milestoneID return committer.Commit() } -// ChangeMilestoneStatus changes the milestone open/closed status. -func ChangeMilestoneStatus(ctx context.Context, m *Milestone, isClosed bool) (err error) { - ctx, committer, err := db.TxContext(ctx) - if err != nil { - return err - } - defer committer.Close() - - if err := changeMilestoneStatus(ctx, m, isClosed); err != nil { - return err - } - - return committer.Commit() -} - func changeMilestoneStatus(ctx context.Context, m *Milestone, isClosed bool) error { m.IsClosed = isClosed if isClosed { diff --git a/models/issues/milestone_test.go b/models/issues/milestone_test.go index 314cba308c..c83450e9db 100644 --- a/models/issues/milestone_test.go +++ b/models/issues/milestone_test.go @@ -298,17 +298,16 @@ func TestNewMilestone(t *testing.T) { unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{}) } -func TestChangeMilestoneStatus(t *testing.T) { +func TestChangeMilestoneStatusByRepoIDAndID(t *testing.T) { require.NoError(t, unittest.PrepareTestDatabase()) - milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}) - require.NoError(t, issues_model.ChangeMilestoneStatus(db.DefaultContext, milestone, true)) - unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}, "is_closed=1") - unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{}) + require.NoError(t, issues_model.ChangeMilestoneStatusByRepoIDAndID(db.DefaultContext, 1, 1, true)) + unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1, IsClosed: true}) + unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: 1}, &issues_model.Milestone{}) - require.NoError(t, issues_model.ChangeMilestoneStatus(db.DefaultContext, milestone, false)) + require.NoError(t, issues_model.ChangeMilestoneStatusByRepoIDAndID(db.DefaultContext, 1, 1, false)) unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}, "is_closed=0") - unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{}) + unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: 1}, &issues_model.Milestone{}) } func TestDeleteMilestoneByRepoID(t *testing.T) { diff --git a/models/issues/pull.go b/models/issues/pull.go index 13eafccdc7..708dff9b8e 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -575,7 +575,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *Iss Attachments: uuids, IsPull: true, }); err != nil { - if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) || IsErrNewIssueInsert(err) { + if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) { return err } return fmt.Errorf("newIssue: %w", err) diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go index 2fe4eb8e78..652007a78b 100644 --- a/routers/api/v1/user/gpg_key.go +++ b/routers/api/v1/user/gpg_key.go @@ -303,11 +303,7 @@ func DeleteGPGKey(ctx *context.APIContext) { } if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.ParamsInt64(":id")); err != nil { - if asymkey_model.IsErrGPGKeyAccessDenied(err) { - ctx.Error(http.StatusForbidden, "", "You do not have access to this key") - } else { - ctx.Error(http.StatusInternalServerError, "DeleteGPGKey", err) - } + ctx.Error(http.StatusInternalServerError, "DeleteGPGKey", err) return } @@ -317,8 +313,6 @@ func DeleteGPGKey(ctx *context.APIContext) { // HandleAddGPGKeyError handle add GPGKey error func HandleAddGPGKeyError(ctx *context.APIContext, err error, token string) { switch { - case asymkey_model.IsErrGPGKeyAccessDenied(err): - ctx.Error(http.StatusUnprocessableEntity, "GPGKeyAccessDenied", "You do not have access to this GPG key") case asymkey_model.IsErrGPGKeyIDAlreadyUsed(err): ctx.Error(http.StatusUnprocessableEntity, "GPGKeyIDAlreadyUsed", "A key with the same id already exists") case asymkey_model.IsErrGPGKeyParsing(err):