MCPcopy Create free account
hub / github.com/gogs/gogs / SetRepoPerms

Method SetRepoPerms

internal/database/permissions.go:113–131  ·  view source on GitHub ↗

SetRepoPerms does a full update to which users have which level of access to given repository. Keys of the "accessMap" are user IDs.

(ctx context.Context, repoID int64, accessMap map[int64]AccessMode)

Source from the content-addressed store, hash-verified

111// SetRepoPerms does a full update to which users have which level of access to
112// given repository. Keys of the "accessMap" are user IDs.
113func (s *PermissionsStore) SetRepoPerms(ctx context.Context, repoID int64, accessMap map[int64]AccessMode) error {
114 records := make([]*Access, 0, len(accessMap))
115 for userID, mode := range accessMap {
116 records = append(records, &Access{
117 UserID: userID,
118 RepoID: repoID,
119 Mode: mode,
120 })
121 }
122
123 return s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
124 err := tx.Where("repo_id = ?", repoID).Delete(new(Access)).Error
125 if err != nil {
126 return err
127 }
128
129 return tx.Create(&records).Error
130 })
131}

Callers 5

permsAccessModeFunction · 0.80
permsAuthorizeFunction · 0.80
permsSetRepoPermsFunction · 0.80
reposGetByCollaboratorIDFunction · 0.80

Calls 4

appendFunction · 0.85
DeleteMethod · 0.80
WhereMethod · 0.80
CreateMethod · 0.45

Tested by 5

permsAccessModeFunction · 0.64
permsAuthorizeFunction · 0.64
permsSetRepoPermsFunction · 0.64
reposGetByCollaboratorIDFunction · 0.64