From 84076211b3da9bd8ab9ba30806276f0faff6d5fb Mon Sep 17 00:00:00 2001 From: sebastian-sauer Date: Sun, 27 Jan 2019 10:25:21 +0100 Subject: [PATCH] Config option to disable automatic repo watching (#5852) Add a new config option to enable / disable the automatic watching of repos for new repositories and if a user is added to a team. Fixes #653 Signed-off-by: Sebastian Sauer --- custom/conf/app.ini.sample | 4 +++ .../doc/advanced/config-cheat-sheet.en-us.md | 1 + models/org_team.go | 25 ++++++++++++------- models/repo.go | 13 ++++++---- modules/setting/setting.go | 2 ++ 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index b89c5b5e965..6b46456f4ef 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -368,6 +368,10 @@ DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME = true NO_REPLY_ADDRESS = noreply.example.org ; Show Registration button SHOW_REGISTRATION_BUTTON = true +; Default value for AutoWatchNewRepos +; When adding a repo to a team or creating a new repo all team members will watch the +; repo automatically if enabled +AUTO_WATCH_NEW_REPOS = true [webhook] ; Hook task queue length, increase if webhook shooting starts hanging diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 15f90769bc3..7d7f4d9e0a7 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -207,6 +207,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `EMAIL_DOMAIN_WHITELIST`: **\**: If non-empty, list of domain names that can only be used to register on this instance. - `SHOW_REGISTRATION_BUTTON`: **! DISABLE\_REGISTRATION**: Show Registration Button +- `AUTO_WATCH_NEW_REPOS`: **true** Enable this to let all organisation users watch new repos when they are created ## Webhook (`webhook`) diff --git a/models/org_team.go b/models/org_team.go index 2ab807b49b3..22fb6eae24f 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -11,6 +11,8 @@ import ( "strings" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" + "github.com/go-xorm/xorm" ) @@ -123,14 +125,18 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) { return fmt.Errorf("recalculateAccesses: %v", err) } - if err = t.getMembers(e); err != nil { - return fmt.Errorf("getMembers: %v", err) - } - for _, u := range t.Members { - if err = watchRepo(e, u.ID, repo.ID, true); err != nil { - return fmt.Errorf("watchRepo: %v", err) + // Make all team members watch this repo if enabled in global settings + if setting.Service.AutoWatchNewRepos { + if err = t.getMembers(e); err != nil { + return fmt.Errorf("getMembers: %v", err) + } + for _, u := range t.Members { + if err = watchRepo(e, u.ID, repo.ID, true); err != nil { + return fmt.Errorf("watchRepo: %v", err) + } } } + return nil } @@ -618,9 +624,10 @@ func AddTeamMember(team *Team, userID int64) error { if err := repo.recalculateTeamAccesses(sess, 0); err != nil { return err } - - if err = watchRepo(sess, userID, repo.ID, true); err != nil { - return err + if setting.Service.AutoWatchNewRepos { + if err = watchRepo(sess, userID, repo.ID, true); err != nil { + return err + } } } diff --git a/models/repo.go b/models/repo.go index fc566ab2d3a..51ea1c94bc6 100644 --- a/models/repo.go +++ b/models/repo.go @@ -34,8 +34,8 @@ import ( "github.com/Unknwon/com" "github.com/go-xorm/builder" "github.com/go-xorm/xorm" - "github.com/mcuadros/go-version" - "gopkg.in/ini.v1" + version "github.com/mcuadros/go-version" + ini "gopkg.in/ini.v1" ) var repoWorkingPool = sync.NewExclusivePool() @@ -1353,9 +1353,12 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err } } - if err = watchRepo(e, doer.ID, repo.ID, true); err != nil { - return fmt.Errorf("watchRepo: %v", err) - } else if err = newRepoAction(e, u, repo); err != nil { + if setting.Service.AutoWatchNewRepos { + if err = watchRepo(e, doer.ID, repo.ID, true); err != nil { + return fmt.Errorf("watchRepo: %v", err) + } + } + if err = newRepoAction(e, u, repo); err != nil { return fmt.Errorf("newRepoAction: %v", err) } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index ec9fa02c25f..4aca5796175 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -1247,6 +1247,7 @@ var Service struct { DefaultAllowOnlyContributorsToTrackTime bool NoReplyAddress string EnableUserHeatmap bool + AutoWatchNewRepos bool // OpenID settings EnableOpenIDSignIn bool @@ -1281,6 +1282,7 @@ func newService() { Service.DefaultAllowOnlyContributorsToTrackTime = sec.Key("DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME").MustBool(true) Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org") Service.EnableUserHeatmap = sec.Key("ENABLE_USER_HEATMAP").MustBool(true) + Service.AutoWatchNewRepos = sec.Key("AUTO_WATCH_NEW_REPOS").MustBool(true) sec = Cfg.Section("openid") Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock)