From 8ee45eb614eaa4814936a2166addc8c1208ea1f5 Mon Sep 17 00:00:00 2001 From: Bwko Date: Mon, 9 Apr 2018 17:15:32 +0200 Subject: [PATCH] Add EnableTimetracking option to app settings (#3719) --- custom/conf/app.ini.sample | 2 ++ models/repo_issue.go | 10 ++++++++++ modules/setting/setting.go | 6 +++++- options/locale/locale_en-US.ini | 1 + templates/admin/config.tmpl | 12 ++++++++---- templates/repo/settings/options.tmpl | 23 ++++++++++++----------- 6 files changed, 38 insertions(+), 16 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 3bd5a9c27..e2af3c708 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -301,6 +301,8 @@ DEFAULT_KEEP_EMAIL_PRIVATE = false ; Default value for AllowCreateOrganization ; New user will have rights set to create organizations depending on this setting DEFAULT_ALLOW_CREATE_ORGANIZATION = true +; Enable Timetracking +ENABLE_TIMETRACKING = true ; Default value for EnableTimetracking ; Repositories will use timetracking by default depending on this setting DEFAULT_ENABLE_TIMETRACKING = true diff --git a/models/repo_issue.go b/models/repo_issue.go index 10356d2c9..433d0e39b 100644 --- a/models/repo_issue.go +++ b/models/repo_issue.go @@ -13,8 +13,18 @@ import "code.gitea.io/gitea/modules/setting" // |____| |__|__|_| /\___ >____| |__| (____ /\___ >__|_ \\___ >__| // \/ \/ \/ \/ \/ \/ +// CanEnableTimetracker returns true when the server admin enabled time tracking +// This overrules IsTimetrackerEnabled +func (repo *Repository) CanEnableTimetracker() bool { + return setting.Service.EnableTimetracking +} + // IsTimetrackerEnabled returns whether or not the timetracker is enabled. It returns the default value from config if an error occurs. func (repo *Repository) IsTimetrackerEnabled() bool { + if !setting.Service.EnableTimetracking { + return false + } + var u *RepoUnit var err error if u, err = repo.GetUnit(UnitTypeIssues); err != nil { diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 9ba3e5a66..af1a28242 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -1151,6 +1151,7 @@ var Service struct { EnableCaptcha bool DefaultKeepEmailPrivate bool DefaultAllowCreateOrganization bool + EnableTimetracking bool DefaultEnableTimetracking bool DefaultAllowOnlyContributorsToTrackTime bool NoReplyAddress string @@ -1174,7 +1175,10 @@ func newService() { Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool() Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool() Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true) - Service.DefaultEnableTimetracking = sec.Key("DEFAULT_ENABLE_TIMETRACKING").MustBool(true) + Service.EnableTimetracking = sec.Key("ENABLE_TIMETRACKING").MustBool(true) + if Service.EnableTimetracking { + Service.DefaultEnableTimetracking = sec.Key("DEFAULT_ENABLE_TIMETRACKING").MustBool(true) + } Service.DefaultAllowOnlyContributorsToTrackTime = sec.Key("DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME").MustBool(true) Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org") diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 136b5e522..cdeac644c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1435,6 +1435,7 @@ config.active_code_lives = Active Code Lives config.reset_password_code_lives = Reset Password Code Expiry Time config.default_keep_email_private = Default Value for Keep Email Private config.default_allow_create_organization = Default permission to create organizations +config.enable_timetracking = Enable time tracking config.default_enable_timetracking = Enable time tracking by default config.default_allow_only_contributors_to_track_time = Allow only contributors to track time by default config.no_reply_address = No-reply Address diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index 7c353ad30..370325692 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -132,10 +132,14 @@
{{.i18n.Tr "admin.config.default_allow_create_organization"}}
-
{{.i18n.Tr "admin.config.default_enable_timetracking"}}
-
-
{{.i18n.Tr "admin.config.default_allow_only_contributors_to_track_time"}}
-
+
{{.i18n.Tr "admin.config.enable_timetracking"}}
+
+ {{if .Service.EnableTimetracking}} +
{{.i18n.Tr "admin.config.default_enable_timetracking"}}
+
+
{{.i18n.Tr "admin.config.default_allow_only_contributors_to_track_time"}}
+
+ {{end}}
{{.i18n.Tr "admin.config.no_reply_address"}}
{{if .Service.NoReplyAddress}}{{.Service.NoReplyAddress}}{{else}}-{{end}}
diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 8470d6a5e..3e811559e 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -139,19 +139,20 @@
-
-
- - + {{if .Repository.CanEnableTimetracker}} +
+
+ + +
-
-
-
- - - +
+
+ + +
-
+ {{end}}