mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-22 15:18:30 -04:00
Rename almost all Ctx functions (#22071)
This commit is contained in:
parent
097d4e30b1
commit
68704532c2
78 changed files with 562 additions and 611 deletions
|
@ -13,30 +13,25 @@ import (
|
|||
user_model "code.gitea.io/gitea/models/user"
|
||||
)
|
||||
|
||||
func addCollaborator(ctx context.Context, repo *repo_model.Repository, u *user_model.User) error {
|
||||
collaboration := &repo_model.Collaboration{
|
||||
RepoID: repo.ID,
|
||||
UserID: u.ID,
|
||||
}
|
||||
func AddCollaborator(ctx context.Context, repo *repo_model.Repository, u *user_model.User) error {
|
||||
return db.AutoTx(ctx, func(ctx context.Context) error {
|
||||
collaboration := &repo_model.Collaboration{
|
||||
RepoID: repo.ID,
|
||||
UserID: u.ID,
|
||||
}
|
||||
|
||||
has, err := db.GetByBean(ctx, collaboration)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if has {
|
||||
return nil
|
||||
}
|
||||
collaboration.Mode = perm.AccessModeWrite
|
||||
has, err := db.GetByBean(ctx, collaboration)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if has {
|
||||
return nil
|
||||
}
|
||||
collaboration.Mode = perm.AccessModeWrite
|
||||
|
||||
if err = db.Insert(ctx, collaboration); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = db.Insert(ctx, collaboration); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return access_model.RecalculateUserAccess(ctx, repo, u.ID)
|
||||
}
|
||||
|
||||
// AddCollaborator adds new collaboration to a repository with default access mode.
|
||||
func AddCollaborator(repo *repo_model.Repository, u *user_model.User) error {
|
||||
return db.WithTx(db.DefaultContext, func(ctx context.Context) error {
|
||||
return addCollaborator(ctx, repo, u)
|
||||
return access_model.RecalculateUserAccess(ctx, repo, u.ID)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue