Skip to content

Commit 8d36702

Browse files
committed
merge
1 parent 9fb3d24 commit 8d36702

File tree

11 files changed

+8
-191
lines changed

11 files changed

+8
-191
lines changed

cmd/migrate_storage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func migrateAvatars(dstStorage storage.ObjectStorage) error {
102102
}
103103

104104
func migrateRepoAvatars(dstStorage storage.ObjectStorage) error {
105-
return repo_model.IterateRepository(func(repo *repo_model.Repository) error {
105+
return models.IterateRepository(func(repo *repo_model.Repository) error {
106106
_, err := storage.Copy(dstStorage, repo.CustomAvatarRelativePath(), storage.RepoAvatars, repo.CustomAvatarRelativePath())
107107
return err
108108
})

models/asymkey/gpg_key_commit_verification.go

+2-43
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const (
7070
)
7171

7272
// ParseCommitsWithSignature checks if signaute of commits are corresponding to users gpg keys.
73-
func ParseCommitsWithSignature(oldCommits []*user_model.UserCommit, repoTrustModel TrustModelType, isCodeReader func(*user_model.User) (bool, error)) []*SignCommit {
73+
func ParseCommitsWithSignature(oldCommits []*user_model.UserCommit, repoTrustModel repo_model.TrustModelType, isCodeReader func(*user_model.User) (bool, error)) []*SignCommit {
7474
newCommits := make([]*SignCommit, 0, len(oldCommits))
7575
keyMap := map[string]bool{}
7676

@@ -447,50 +447,9 @@ func hashAndVerifyForKeyID(sig *packet.Signature, payload string, committer *use
447447
}
448448
}
449449

450-
// TrustModelType defines the types of trust model for this repository
451-
type TrustModelType int
452-
453-
// kinds of TrustModel
454-
const (
455-
DefaultTrustModel TrustModelType = iota // default trust model
456-
CommitterTrustModel
457-
CollaboratorTrustModel
458-
CollaboratorCommitterTrustModel
459-
)
460-
461-
// String converts a TrustModelType to a string
462-
func (t TrustModelType) String() string {
463-
switch t {
464-
case DefaultTrustModel:
465-
return "default"
466-
case CommitterTrustModel:
467-
return "committer"
468-
case CollaboratorTrustModel:
469-
return "collaborator"
470-
case CollaboratorCommitterTrustModel:
471-
return "collaboratorcommitter"
472-
}
473-
return "default"
474-
}
475-
476-
// ToTrustModel converts a string to a TrustModelType
477-
func ToTrustModel(model string) TrustModelType {
478-
switch strings.ToLower(strings.TrimSpace(model)) {
479-
case "default":
480-
return DefaultTrustModel
481-
case "collaborator":
482-
return CollaboratorTrustModel
483-
case "committer":
484-
return CommitterTrustModel
485-
case "collaboratorcommitter":
486-
return CollaboratorCommitterTrustModel
487-
}
488-
return DefaultTrustModel
489-
}
490-
491450
// CalculateTrustStatus will calculate the TrustStatus for a commit verification within a repository
492451
// There are several trust models in Gitea
493-
func CalculateTrustStatus(verification *CommitVerification, repoTrustModel TrustModelType, isCodeReader func(*user_model.User) (bool, error), keyMap *map[string]bool) (err error) {
452+
func CalculateTrustStatus(verification *CommitVerification, repoTrustModel repo_model.TrustModelType, isCodeReader func(*user_model.User) (bool, error), keyMap *map[string]bool) (err error) {
494453
if !verification.Verified {
495454
return
496455
}

models/asymkey/ssh_key_deploy.go

-64
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111

1212
"code.gitea.io/gitea/models/db"
1313
"code.gitea.io/gitea/models/perm"
14-
repo_model "code.gitea.io/gitea/models/repo"
15-
user_model "code.gitea.io/gitea/models/user"
1614
"code.gitea.io/gitea/modules/timeutil"
1715

1816
"xorm.io/builder"
@@ -211,68 +209,6 @@ func UpdateDeployKey(key *DeployKey) error {
211209
return err
212210
}
213211

214-
// DeleteDeployKey deletes deploy key from its repository authorized_keys file if needed.
215-
func DeleteDeployKey(doer *user_model.User, id int64) error {
216-
ctx, committer, err := db.TxContext()
217-
if err != nil {
218-
return err
219-
}
220-
defer committer.Close()
221-
222-
if err := deleteDeployKey(ctx, doer, id); err != nil {
223-
return err
224-
}
225-
return committer.Commit()
226-
}
227-
228-
func deleteDeployKey(ctx context.Context, doer *user_model.User, id int64) error {
229-
sess := db.GetEngine(ctx)
230-
key, err := getDeployKeyByID(sess, id)
231-
if err != nil {
232-
if IsErrDeployKeyNotExist(err) {
233-
return nil
234-
}
235-
return fmt.Errorf("GetDeployKeyByID: %v", err)
236-
}
237-
238-
// Check if user has access to delete this key.
239-
if !doer.IsAdmin {
240-
repo, err := repo_model.GetRepositoryByIDCtx(ctx, key.RepoID)
241-
if err != nil {
242-
return fmt.Errorf("repo_model.GetRepositoryByID: %v", err)
243-
}
244-
has, err := isUserRepoAdmin(sess, repo, doer)
245-
if err != nil {
246-
return fmt.Errorf("GetUserRepoPermission: %v", err)
247-
} else if !has {
248-
return ErrKeyAccessDenied{doer.ID, key.ID, "deploy"}
249-
}
250-
}
251-
252-
if _, err = sess.ID(key.ID).Delete(new(DeployKey)); err != nil {
253-
return fmt.Errorf("delete deploy key [%d]: %v", key.ID, err)
254-
}
255-
256-
// Check if this is the last reference to same key content.
257-
has, err := sess.
258-
Where("key_id = ?", key.KeyID).
259-
Get(new(DeployKey))
260-
if err != nil {
261-
return err
262-
} else if !has {
263-
if err = deletePublicKeys(sess, key.KeyID); err != nil {
264-
return err
265-
}
266-
267-
// after deleted the public keys, should rewrite the public keys file
268-
if err = rewriteAllPublicKeys(sess); err != nil {
269-
return err
270-
}
271-
}
272-
273-
return nil
274-
}
275-
276212
// ListDeployKeysOptions are options for ListDeployKeys
277213
type ListDeployKeysOptions struct {
278214
db.ListOptions

models/repo.go

+1-29
Original file line numberDiff line numberDiff line change
@@ -416,17 +416,8 @@ type CreateRepoOptions struct {
416416
IsMirror bool
417417
IsTemplate bool
418418
AutoInit bool
419-
<<<<<<< HEAD
420419
Status repo_model.RepositoryStatus
421420
TrustModel repo_model.TrustModelType
422-
=======
423-
Status RepositoryStatus
424-
<<<<<<< HEAD
425-
TrustModel keys.TrustModelType
426-
>>>>>>> 3db02666b (Move keys to models/keys)
427-
=======
428-
TrustModel asymkey_model.TrustModelType
429-
>>>>>>> 98e1e13cc (Fix package alias)
430421
MirrorInterval string
431422
}
432423

@@ -872,11 +863,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
872863
}
873864
var needRewriteKeysFile = len(deployKeys) > 0
874865
for _, dKey := range deployKeys {
875-
<<<<<<< HEAD
876-
if err := deleteDeployKey(ctx, doer, dKey.ID); err != nil {
877-
=======
878866
if err := DeleteDeployKey(ctx, doer, dKey.ID); err != nil {
879-
>>>>>>> 3db02666b (Move keys to models/keys)
880867
return fmt.Errorf("deleteDeployKeys: %v", err)
881868
}
882869
}
@@ -1344,21 +1331,6 @@ func UpdateRepositoryCols(repo *repo_model.Repository, cols ...string) error {
13441331
return updateRepositoryCols(db.GetEngine(db.DefaultContext), repo, cols...)
13451332
}
13461333

1347-
<<<<<<< HEAD
1348-
=======
1349-
// GetTrustModel will get the TrustModel for the repo or the default trust model
1350-
func (repo *Repository) GetTrustModel() asymkey_model.TrustModelType {
1351-
trustModel := repo.TrustModel
1352-
if trustModel == asymkey_model.DefaultTrustModel {
1353-
trustModel = asymkey_model.ToTrustModel(setting.Repository.Signing.DefaultTrustModel)
1354-
if trustModel == asymkey_model.DefaultTrustModel {
1355-
return asymkey_model.CollaboratorTrustModel
1356-
}
1357-
}
1358-
return trustModel
1359-
}
1360-
1361-
>>>>>>> 3db02666b (Move keys to models/keys)
13621334
func updateUserStarNumbers(users []user_model.User) error {
13631335
ctx, committer, err := db.TxContext()
13641336
if err != nil {
@@ -1458,7 +1430,7 @@ func DeleteDeployKey(ctx context.Context, doer *user_model.User, id int64) error
14581430

14591431
// Check if user has access to delete this key.
14601432
if !doer.IsAdmin {
1461-
repo, err := getRepositoryByID(sess, key.RepoID)
1433+
repo, err := repo_model.GetRepositoryByIDCtx(ctx, key.RepoID)
14621434
if err != nil {
14631435
return fmt.Errorf("GetRepositoryByID: %v", err)
14641436
}

models/statistic.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,8 @@ func GetStatistic() (stats Statistic) {
4848
e := db.GetEngine(db.DefaultContext)
4949
stats.Counter.User = user_model.CountUsers()
5050
stats.Counter.Org = CountOrganizations()
51-
<<<<<<< HEAD
52-
<<<<<<< HEAD
53-
stats.Counter.PublicKey, _ = e.Count(new(PublicKey))
54-
stats.Counter.Repo = repo_model.CountRepositories(true)
55-
=======
56-
stats.Counter.PublicKey, _ = e.Count(new(keys.PublicKey))
57-
=======
5851
stats.Counter.PublicKey, _ = e.Count(new(asymkey_model.PublicKey))
59-
>>>>>>> c486d0ca6 (Rename models/keys -> models/asymkey)
60-
stats.Counter.Repo = CountRepositories(true)
61-
>>>>>>> 3db02666b (Move keys to models/keys)
52+
stats.Counter.Repo = repo_model.CountRepositories(true)
6253
stats.Counter.Watch, _ = e.Count(new(Watch))
6354
stats.Counter.Star, _ = e.Count(new(Star))
6455
stats.Counter.Action, _ = e.Count(new(Action))

routers/api/v1/repo/key.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"net/http"
1111
"net/url"
1212

13-
"code.gitea.io/gitea/models"
1413
asymkey_model "code.gitea.io/gitea/models/asymkey"
1514
"code.gitea.io/gitea/models/db"
1615
"code.gitea.io/gitea/models/perm"
@@ -25,15 +24,7 @@ import (
2524
)
2625

2726
// appendPrivateInformation appends the owner and key type information to api.PublicKey
28-
<<<<<<< HEAD
29-
<<<<<<< HEAD
30-
func appendPrivateInformation(apiKey *api.DeployKey, key *models.DeployKey, repository *repo_model.Repository) (*api.DeployKey, error) {
31-
=======
32-
func appendPrivateInformation(apiKey *api.DeployKey, key *keys_model.DeployKey, repository *models.Repository) (*api.DeployKey, error) {
33-
>>>>>>> 3db02666b (Move keys to models/keys)
34-
=======
35-
func appendPrivateInformation(apiKey *api.DeployKey, key *asymkey_model.DeployKey, repository *models.Repository) (*api.DeployKey, error) {
36-
>>>>>>> c486d0ca6 (Rename models/keys -> models/asymkey)
27+
func appendPrivateInformation(apiKey *api.DeployKey, key *asymkey_model.DeployKey, repository *repo_model.Repository) (*api.DeployKey, error) {
3728
apiKey.ReadOnly = key.Mode == perm.AccessModeRead
3829
if repository.ID == key.RepoID {
3930
apiKey.Repository = convert.ToRepo(repository, key.Mode)

routers/api/v1/repo/repo.go

-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"time"
1313

1414
"code.gitea.io/gitea/models"
15-
asymkey_model "code.gitea.io/gitea/models/asymkey"
1615
"code.gitea.io/gitea/models/db"
1716
"code.gitea.io/gitea/models/perm"
1817
repo_model "code.gitea.io/gitea/models/repo"
@@ -258,15 +257,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
258257
IsPrivate: opt.Private,
259258
AutoInit: opt.AutoInit,
260259
DefaultBranch: opt.DefaultBranch,
261-
<<<<<<< HEAD
262-
<<<<<<< HEAD
263260
TrustModel: repo_model.ToTrustModel(opt.TrustModel),
264-
=======
265-
TrustModel: keys_model.ToTrustModel(opt.TrustModel),
266-
>>>>>>> 3db02666b (Move keys to models/keys)
267-
=======
268-
TrustModel: asymkey_model.ToTrustModel(opt.TrustModel),
269-
>>>>>>> c486d0ca6 (Rename models/keys -> models/asymkey)
270261
IsTemplate: opt.Template,
271262
})
272263
if err != nil {

routers/web/repo/repo.go

-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"time"
1414

1515
"code.gitea.io/gitea/models"
16-
asymkey_model "code.gitea.io/gitea/models/asymkey"
1716
"code.gitea.io/gitea/models/db"
1817
repo_model "code.gitea.io/gitea/models/repo"
1918
"code.gitea.io/gitea/models/unit"
@@ -262,15 +261,7 @@ func CreatePost(ctx *context.Context) {
262261
DefaultBranch: form.DefaultBranch,
263262
AutoInit: form.AutoInit,
264263
IsTemplate: form.Template,
265-
<<<<<<< HEAD
266-
<<<<<<< HEAD
267264
TrustModel: repo_model.ToTrustModel(form.TrustModel),
268-
=======
269-
TrustModel: keys_model.ToTrustModel(form.TrustModel),
270-
>>>>>>> 3db02666b (Move keys to models/keys)
271-
=======
272-
TrustModel: asymkey_model.ToTrustModel(form.TrustModel),
273-
>>>>>>> c486d0ca6 (Rename models/keys -> models/asymkey)
274265
})
275266
if err == nil {
276267
log.Trace("Repository created [%d]: %s/%s", repo.ID, ctxUser.Name, repo.Name)

routers/web/repo/setting.go

-9
Original file line numberDiff line numberDiff line change
@@ -478,16 +478,7 @@ func SettingsPost(ctx *context.Context) {
478478

479479
case "signing":
480480
changed := false
481-
482-
<<<<<<< HEAD
483-
<<<<<<< HEAD
484481
trustModel := repo_model.ToTrustModel(form.TrustModel)
485-
=======
486-
trustModel := keys_model.ToTrustModel(form.TrustModel)
487-
>>>>>>> 3db02666b (Move keys to models/keys)
488-
=======
489-
trustModel := asymkey_model.ToTrustModel(form.TrustModel)
490-
>>>>>>> c486d0ca6 (Rename models/keys -> models/asymkey)
491482
if trustModel != repo.TrustModel {
492483
repo.TrustModel = trustModel
493484
changed = true

services/repository/archiver/archiver.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"strings"
1515
"time"
1616

17-
"code.gitea.io/gitea/models"
1817
"code.gitea.io/gitea/models/db"
1918
repo_model "code.gitea.io/gitea/models/repo"
2019
"code.gitea.io/gitea/modules/git"
@@ -171,7 +170,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
171170
rd.Close()
172171
}()
173172
var done = make(chan error)
174-
repo, err := models.GetRepositoryByID(archiver.RepoID)
173+
repo, err := repo_model.GetRepositoryByID(archiver.RepoID)
175174
if err != nil {
176175
return nil, fmt.Errorf("archiver.LoadRepo failed: %v", err)
177176
}

services/repository/repository.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ func CreateRepository(doer, owner *user_model.User, opts models.CreateRepoOption
3131
}
3232

3333
// DeleteRepository deletes a repository for a user or organization.
34-
<<<<<<< HEAD
35-
func DeleteRepository(doer *user_model.User, repo *repo_model.Repository) error {
36-
=======
37-
func DeleteRepository(doer *user_model.User, repo *models.Repository, notify bool) error {
38-
>>>>>>> 3db02666b (Move keys to models/keys)
34+
func DeleteRepository(doer *user_model.User, repo *repo_model.Repository, notify bool) error {
3935
if err := pull_service.CloseRepoBranchesPulls(doer, repo); err != nil {
4036
log.Error("CloseRepoBranchesPulls failed: %v", err)
4137
}

0 commit comments

Comments
 (0)