summaryrefslogtreecommitdiffstats
path: root/models/user.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-12-10 12:37:53 -0500
committerUnknwon <u@gogs.io>2015-12-10 12:37:53 -0500
commit2a0bb1fa906a4d135ed88de4f705c3ab7214e60c (patch)
tree37d207458c999c5789fd6ca3a2c62d6700ed81b7 /models/user.go
parentc6083c335e53a860fd4c500a86dcdda49a16515e (diff)
downloadgitea-2a0bb1fa906a4d135ed88de4f705c3ab7214e60c.tar.gz
gitea-2a0bb1fa906a4d135ed88de4f705c3ab7214e60c.zip
#1575 Limit repo creation
Diffstat (limited to 'models/user.go')
-rw-r--r--models/user.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/models/user.go b/models/user.go
index f19e33039b..3ff525c589 100644
--- a/models/user.go
+++ b/models/user.go
@@ -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