#1575 Limit repo creation

This commit is contained in:
Unknwon 2015-12-10 12:37:53 -05:00
parent c6083c335e
commit 2a0bb1fa90
15 changed files with 73 additions and 14 deletions

View file

@ -75,6 +75,8 @@ type User struct {
// Remember visibility choice for convenience, true for private
LastRepoVisibility bool
// Maximum repository creation limit, 0 means use gloabl default
MaxRepoCreation int `xorm:"NOT NULL"`
// Permissions.
IsActive bool
@ -101,6 +103,12 @@ type User struct {
Members []*User `xorm:"-"`
}
func (u *User) BeforeUpdate() {
if u.MaxRepoCreation < 0 {
u.MaxRepoCreation = 0
}
}
func (u *User) AfterSet(colName string, _ xorm.Cell) {
switch colName {
case "full_name":
@ -116,6 +124,20 @@ func (u *User) HasForkedRepo(repoID int64) bool {
return has
}
func (u *User) RepoCreationNum() int {
if u.MaxRepoCreation == 0 {
return setting.Repository.MaxCreationLimit
}
return u.MaxRepoCreation
}
func (u *User) CanCreateRepo() bool {
if u.MaxRepoCreation == 0 {
return u.NumRepos < setting.Repository.MaxCreationLimit
}
return u.NumRepos < u.MaxRepoCreation
}
// CanEditGitHook returns true if user can edit Git hooks.
func (u *User) CanEditGitHook() bool {
return u.IsAdmin || u.AllowGitHook