Browse Source

Add EnableTimetracking option to app settings (#3719)

for-closed-social
Bwko 6 years ago
committed by Lunny Xiao
parent
commit
8ee45eb614
6 changed files with 38 additions and 16 deletions
  1. +2
    -0
      custom/conf/app.ini.sample
  2. +10
    -0
      models/repo_issue.go
  3. +5
    -1
      modules/setting/setting.go
  4. +1
    -0
      options/locale/locale_en-US.ini
  5. +8
    -4
      templates/admin/config.tmpl
  6. +12
    -11
      templates/repo/settings/options.tmpl

+ 2
- 0
custom/conf/app.ini.sample View File

@ -301,6 +301,8 @@ DEFAULT_KEEP_EMAIL_PRIVATE = false
; Default value for AllowCreateOrganization ; Default value for AllowCreateOrganization
; New user will have rights set to create organizations depending on this setting ; New user will have rights set to create organizations depending on this setting
DEFAULT_ALLOW_CREATE_ORGANIZATION = true DEFAULT_ALLOW_CREATE_ORGANIZATION = true
; Enable Timetracking
ENABLE_TIMETRACKING = true
; Default value for EnableTimetracking ; Default value for EnableTimetracking
; Repositories will use timetracking by default depending on this setting ; Repositories will use timetracking by default depending on this setting
DEFAULT_ENABLE_TIMETRACKING = true DEFAULT_ENABLE_TIMETRACKING = true

+ 10
- 0
models/repo_issue.go View File

@ -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. // 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 { func (repo *Repository) IsTimetrackerEnabled() bool {
if !setting.Service.EnableTimetracking {
return false
}
var u *RepoUnit var u *RepoUnit
var err error var err error
if u, err = repo.GetUnit(UnitTypeIssues); err != nil { if u, err = repo.GetUnit(UnitTypeIssues); err != nil {

+ 5
- 1
modules/setting/setting.go View File

@ -1151,6 +1151,7 @@ var Service struct {
EnableCaptcha bool EnableCaptcha bool
DefaultKeepEmailPrivate bool DefaultKeepEmailPrivate bool
DefaultAllowCreateOrganization bool DefaultAllowCreateOrganization bool
EnableTimetracking bool
DefaultEnableTimetracking bool DefaultEnableTimetracking bool
DefaultAllowOnlyContributorsToTrackTime bool DefaultAllowOnlyContributorsToTrackTime bool
NoReplyAddress string NoReplyAddress string
@ -1174,7 +1175,10 @@ func newService() {
Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool() Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool()
Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool() Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true) 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.DefaultAllowOnlyContributorsToTrackTime = sec.Key("DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME").MustBool(true)
Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org") Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org")

+ 1
- 0
options/locale/locale_en-US.ini View File

@ -1435,6 +1435,7 @@ config.active_code_lives = Active Code Lives
config.reset_password_code_lives = Reset Password Code Expiry Time config.reset_password_code_lives = Reset Password Code Expiry Time
config.default_keep_email_private = Default Value for Keep Email Private config.default_keep_email_private = Default Value for Keep Email Private
config.default_allow_create_organization = Default permission to create organizations 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_enable_timetracking = Enable time tracking by default
config.default_allow_only_contributors_to_track_time = Allow only contributors to track time 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 config.no_reply_address = No-reply Address

+ 8
- 4
templates/admin/config.tmpl View File

@ -132,10 +132,14 @@
<dd><i class="fa fa{{if .Service.DefaultKeepEmailPrivate}}-check{{end}}-square-o"></i></dd> <dd><i class="fa fa{{if .Service.DefaultKeepEmailPrivate}}-check{{end}}-square-o"></i></dd>
<dt>{{.i18n.Tr "admin.config.default_allow_create_organization"}}</dt> <dt>{{.i18n.Tr "admin.config.default_allow_create_organization"}}</dt>
<dd><i class="fa fa{{if .Service.DefaultAllowCreateOrganization}}-check{{end}}-square-o"></i></dd> <dd><i class="fa fa{{if .Service.DefaultAllowCreateOrganization}}-check{{end}}-square-o"></i></dd>
<dt>{{.i18n.Tr "admin.config.default_enable_timetracking"}}</dt>
<dd><i class="fa fa{{if .Service.DefaultEnableTimetracking}}-check{{end}}-square-o"></i></dd>
<dt>{{.i18n.Tr "admin.config.default_allow_only_contributors_to_track_time"}}</dt>
<dd><i class="fa fa{{if .Service.DefaultAllowOnlyContributorsToTrackTime}}-check{{end}}-square-o"></i></dd>
<dt>{{.i18n.Tr "admin.config.enable_timetracking"}}</dt>
<dd><i class="fa fa{{if .Service.EnableTimetracking}}-check{{end}}-square-o"></i></dd>
{{if .Service.EnableTimetracking}}
<dt>{{.i18n.Tr "admin.config.default_enable_timetracking"}}</dt>
<dd><i class="fa fa{{if .Service.DefaultEnableTimetracking}}-check{{end}}-square-o"></i></dd>
<dt>{{.i18n.Tr "admin.config.default_allow_only_contributors_to_track_time"}}</dt>
<dd><i class="fa fa{{if .Service.DefaultAllowOnlyContributorsToTrackTime}}-check{{end}}-square-o"></i></dd>
{{end}}
<dt>{{.i18n.Tr "admin.config.no_reply_address"}}</dt> <dt>{{.i18n.Tr "admin.config.no_reply_address"}}</dt>
<dd>{{if .Service.NoReplyAddress}}{{.Service.NoReplyAddress}}{{else}}-{{end}}</dd> <dd>{{if .Service.NoReplyAddress}}{{.Service.NoReplyAddress}}{{else}}-{{end}}</dd>
<div class="ui divider"></div> <div class="ui divider"></div>

+ 12
- 11
templates/repo/settings/options.tmpl View File

@ -139,19 +139,20 @@
</div> </div>
</div> </div>
<div class="field {{if (.Repository.UnitEnabled $.UnitTypeExternalTracker)}}disabled{{end}}" id="internal_issue_box"> <div class="field {{if (.Repository.UnitEnabled $.UnitTypeExternalTracker)}}disabled{{end}}" id="internal_issue_box">
<div class="field">
<div class="ui checkbox">
<input name="enable_timetracker" class="enable-system" data-target="#only_contributors" type="checkbox" {{if .Repository.IsTimetrackerEnabled}}checked{{end}}>
<label>{{.i18n.Tr "repo.settings.enable_timetracker"}}</label>
{{if .Repository.CanEnableTimetracker}}
<div class="field">
<div class="ui checkbox">
<input name="enable_timetracker" class="enable-system" data-target="#only_contributors" type="checkbox" {{if .Repository.IsTimetrackerEnabled}}checked{{end}}>
<label>{{.i18n.Tr "repo.settings.enable_timetracker"}}</label>
</div>
</div> </div>
</div>
<div class="field {{if not .Repository.IsTimetrackerEnabled}}disabled{{end}}" id="only_contributors">
<div class="ui checkbox">
<input name="allow_only_contributors_to_track_time" type="checkbox" {{if .Repository.AllowOnlyContributorsToTrackTime}}checked{{end}}>
<label>{{.i18n.Tr "repo.settings.allow_only_contributors_to_track_time"}}</label>
<div class="field {{if not .Repository.IsTimetrackerEnabled}}disabled{{end}}" id="only_contributors">
<div class="ui checkbox">
<input name="allow_only_contributors_to_track_time" type="checkbox" {{if .Repository.AllowOnlyContributorsToTrackTime}}checked{{end}}>
<label>{{.i18n.Tr "repo.settings.allow_only_contributors_to_track_time"}}</label>
</div>
</div> </div>
</div>
{{end}}
</div> </div>
<div class="field"> <div class="field">
<div class="ui radio checkbox"> <div class="ui radio checkbox">

Loading…
Cancel
Save