Skip to content

Commit f44543a

Browse files
authored
Disable Stars config option (#14653)
* Add config option to disable stars * Replace "stars" with watched in user profile * Add documentation
1 parent af2adb4 commit f44543a

File tree

16 files changed

+83
-27
lines changed

16 files changed

+83
-27
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ PREFIX_ARCHIVE_FILES = true
7070
DISABLE_MIRRORS = false
7171
; Disable migrating feature.
7272
DISABLE_MIGRATIONS = false
73+
; Disable stars feature.
74+
DISABLE_STARS = false
7375
; The default branch name of new repositories
7476
DEFAULT_BRANCH = master
7577
; Allow adoption of unadopted repositories

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
7575
- `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository.
7676
- `DISABLE_MIRRORS`: **false**: Disable the creation of **new** mirrors. Pre-existing mirrors remain valid.
7777
- `DISABLE_MIGRATIONS`: **false**: Disable migrating feature.
78+
- `DISABLE_STARS`: **false**: Disable stars feature.
7879
- `DEFAULT_BRANCH`: **master**: Default branch name of all repositories.
7980
- `ALLOW_ADOPTION_OF_UNADOPTED_REPOSITORIES`: **false**: Allow non-admin users to adopt unadopted repositories
8081
- `ALLOW_DELETION_OF_UNADOPTED_REPOSITORIES`: **false**: Allow non-admin users to delete unadopted repositories

models/repo_list.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ type SearchRepoOptions struct {
143143
OrderBy SearchOrderBy
144144
Private bool // Include private repositories in results
145145
StarredByID int64
146+
WatchedByID int64
146147
AllPublic bool // Include also all public repositories of users and public organisations
147148
AllLimited bool // Include also all public repositories of limited organisations
148149
// None -> include public and private
@@ -241,6 +242,11 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
241242
cond = cond.And(builder.In("id", builder.Select("repo_id").From("star").Where(builder.Eq{"uid": opts.StarredByID})))
242243
}
243244

245+
// Restrict to watched repositories
246+
if opts.WatchedByID > 0 {
247+
cond = cond.And(builder.In("id", builder.Select("repo_id").From("watch").Where(builder.Eq{"user_id": opts.WatchedByID})))
248+
}
249+
244250
// Restrict repositories to those the OwnerID owns or contributes to as per opts.Collaborate
245251
if opts.OwnerID > 0 {
246252
accessCond := builder.NewCond()

modules/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ func Contexter() func(next http.Handler) http.Handler {
704704
ctx.Data["EnableSwagger"] = setting.API.EnableSwagger
705705
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
706706
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
707+
ctx.Data["DisableStars"] = setting.Repository.DisableStars
707708

708709
ctx.Data["ManifestData"] = setting.ManifestData
709710

modules/setting/repository.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
PrefixArchiveFiles bool
4444
DisableMirrors bool
4545
DisableMigrations bool
46+
DisableStars bool `ini:"DISABLE_STARS"`
4647
DefaultBranch string
4748
AllowAdoptionOfUnadoptedRepositories bool
4849
AllowDeleteOfUnadoptedRepositories bool
@@ -154,6 +155,7 @@ var (
154155
PrefixArchiveFiles: true,
155156
DisableMirrors: false,
156157
DisableMigrations: false,
158+
DisableStars: false,
157159
DefaultBranch: "master",
158160

159161
// Repository editor settings

modules/structs/settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type GeneralRepoSettings struct {
99
MirrorsDisabled bool `json:"mirrors_disabled"`
1010
HTTPGitDisabled bool `json:"http_git_disabled"`
1111
MigrationsDisabled bool `json:"migrations_disabled"`
12+
StarsDisabled bool `json:"stars_disabled"`
1213
TimeTrackingDisabled bool `json:"time_tracking_disabled"`
1314
LFSDisabled bool `json:"lfs_disabled"`
1415
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ repositories = Repositories
421421
activity = Public Activity
422422
followers = Followers
423423
starred = Starred Repositories
424+
watched = Watched Repositories
424425
projects = Projects
425426
following = Following
426427
follow = Follow

routers/api/v1/settings/settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func GetGeneralRepoSettings(ctx *context.APIContext) {
6060
MirrorsDisabled: setting.Repository.DisableMirrors,
6161
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
6262
MigrationsDisabled: setting.Repository.DisableMigrations,
63+
StarsDisabled: setting.Repository.DisableStars,
6364
TimeTrackingDisabled: !setting.Service.EnableTimetracking,
6465
LFSDisabled: !setting.LFS.StartServer,
6566
})

routers/user/profile.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,27 @@ func Profile(ctx *context.Context) {
238238
ctx.ServerError("GetProjects", err)
239239
return
240240
}
241+
case "watching":
242+
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
243+
ListOptions: models.ListOptions{
244+
PageSize: setting.UI.User.RepoPagingNum,
245+
Page: page,
246+
},
247+
Actor: ctx.User,
248+
Keyword: keyword,
249+
OrderBy: orderBy,
250+
Private: ctx.IsSigned,
251+
WatchedByID: ctxUser.ID,
252+
Collaborate: util.OptionalBoolFalse,
253+
TopicOnly: topicOnly,
254+
IncludeDescription: setting.UI.SearchRepoDescription,
255+
})
256+
if err != nil {
257+
ctx.ServerError("SearchRepository", err)
258+
return
259+
}
260+
261+
total = int(count)
241262
default:
242263
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
243264
ListOptions: models.ListOptions{

templates/base/head_navbar.tmpl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,12 @@
157157
{{svg "octicon-person"}}
158158
{{.i18n.Tr "your_profile"}}<!-- Your profile -->
159159
</a>
160-
<a class="item" href="{{AppSubUrl}}/{{.SignedUser.Name}}?tab=stars">
161-
{{svg "octicon-star"}}
162-
{{.i18n.Tr "your_starred"}}
163-
</a>
160+
{{if not .DisableStars}}
161+
<a class="item" href="{{AppSubUrl}}/{{.SignedUser.Name}}?tab=stars">
162+
{{svg "octicon-star"}}
163+
{{.i18n.Tr "your_starred"}}
164+
</a>
165+
{{end}}
164166
<a class="{{if .PageIsUserSettings}}active{{end}} item" href="{{AppSubUrl}}/user/settings">
165167
{{svg "octicon-tools"}}
166168
{{.i18n.Tr "your_settings"}}<!-- Your settings -->

templates/explore/repo_list.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
{{if .PrimaryLanguage }}
4343
<span class="text grey df ac mr-3"><i class="color-icon mr-3" style="background-color: {{.PrimaryLanguage.Color}}"></i>{{ .PrimaryLanguage.Language }}</span>
4444
{{end}}
45-
<span class="text grey df ac mr-3">{{svg "octicon-star" 16 "mr-3"}}{{.NumStars}}</span>
45+
{{if not $.DisableStars}}
46+
<span class="text grey df ac mr-3">{{svg "octicon-star" 16 "mr-3"}}{{.NumStars}}</span>
47+
{{end}}
4648
<span class="text grey df ac mr-3">{{svg "octicon-git-branch" 16 "mr-3"}}{{.NumForks}}</span>
4749
</div>
4850
</div>

templates/explore/repo_search.tmpl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
<a class="{{if eq .SortType "reversealphabetically"}}active{{end}} item" href="{{$.Link}}?sort=reversealphabetically&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
1313
<a class="{{if eq .SortType "recentupdate"}}active{{end}} item" href="{{$.Link}}?sort=recentupdate&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.recentupdate"}}</a>
1414
<a class="{{if eq .SortType "leastupdate"}}active{{end}} item" href="{{$.Link}}?sort=leastupdate&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a>
15-
<a class="{{if eq .SortType "moststars"}}active{{end}} item" href="{{$.Link}}?sort=moststars&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.moststars"}}</a>
16-
<a class="{{if eq .SortType "feweststars"}}active{{end}} item" href="{{$.Link}}?sort=feweststars&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.feweststars"}}</a>
15+
{{if not .DisableStars}}
16+
<a class="{{if eq .SortType "moststars"}}active{{end}} item" href="{{$.Link}}?sort=moststars&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.moststars"}}</a>
17+
<a class="{{if eq .SortType "feweststars"}}active{{end}} item" href="{{$.Link}}?sort=feweststars&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.feweststars"}}</a>
18+
{{end}}
1719
<a class="{{if eq .SortType "mostforks"}}active{{end}} item" href="{{$.Link}}?sort=mostforks&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.mostforks"}}</a>
1820
<a class="{{if eq .SortType "fewestforks"}}active{{end}} item" href="{{$.Link}}?sort=fewestforks&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.fewestforks"}}</a>
1921
</div>

templates/repo/header.tmpl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,19 @@
7171
</a>
7272
</div>
7373
</form>
74-
<form method="post" action="{{$.RepoLink}}/action/{{if $.IsStaringRepo}}un{{end}}star?redirect_to={{$.Link}}">
75-
{{$.CsrfTokenHtml}}
76-
<div class="ui labeled button{{if not $.IsSigned}} poping up{{end}}" tabindex="0"{{if not $.IsSigned}} data-content="{{$.i18n.Tr "repo.star_guest_user" }}" data-position="top center" data-variation="tiny"{{end}}>
77-
<button type="submit" class="ui compact small basic button"{{if not $.IsSigned}} disabled{{end}}>
78-
{{if $.IsStaringRepo}}{{svg "octicon-star-fill"}}{{$.i18n.Tr "repo.unstar"}}{{else}}{{svg "octicon-star"}}{{$.i18n.Tr "repo.star"}}{{end}}
79-
</button>
80-
<a class="ui basic label" href="{{.Link}}/stars">
81-
{{CountFmt .NumStars}}
82-
</a>
83-
</div>
84-
</form>
74+
{{if not $.DisableStars}}
75+
<form method="post" action="{{$.RepoLink}}/action/{{if $.IsStaringRepo}}un{{end}}star?redirect_to={{$.Link}}">
76+
{{$.CsrfTokenHtml}}
77+
<div class="ui labeled button{{if not $.IsSigned}} poping up{{end}}" tabindex="0"{{if not $.IsSigned}} data-content="{{$.i18n.Tr "repo.star_guest_user" }}" data-position="top center" data-variation="tiny"{{end}}>
78+
<button type="submit" class="ui compact small basic button"{{if not $.IsSigned}} disabled{{end}}>
79+
{{if $.IsStaringRepo}}{{svg "octicon-star-fill"}}{{$.i18n.Tr "repo.unstar"}}{{else}}{{svg "octicon-star"}}{{$.i18n.Tr "repo.star"}}{{end}}
80+
</button>
81+
<a class="ui basic label" href="{{.Link}}/stars">
82+
{{CountFmt .NumStars}}
83+
</a>
84+
</div>
85+
</form>
86+
{{end}}
8587
{{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
8688
<div class="ui labeled button{{if not $.CanSignedUserFork}} poping up disabled{{end}}"{{if and (not $.CanSignedUserFork) $.IsSigned}} data-content="{{$.i18n.Tr "repo.fork_from_self"}}" {{else if not $.IsSigned}} data-content="{{$.i18n.Tr "repo.fork_guest_user"}}"{{end}} data-position="top center" data-variation="tiny" tabindex="0">
8789
<a class="ui compact small basic button"{{if $.CanSignedUserFork}} href="{{AppSubUrl}}/repo/fork/{{.ID}}"{{end}}>

templates/swagger/v1_json.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14151,6 +14151,10 @@
1415114151
"type": "boolean",
1415214152
"x-go-name": "MirrorsDisabled"
1415314153
},
14154+
"stars_disabled": {
14155+
"type": "boolean",
14156+
"x-go-name": "StarsDisabled"
14157+
},
1415414158
"time_tracking_disabled": {
1415514159
"type": "boolean",
1415614160
"x-go-name": "TimeTrackingDisabled"

templates/user/dashboard/repolist.tmpl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@
130130
{{svg "octicon-archive" 16 "ml-2"}}
131131
</span>
132132
</div>
133-
<div class="text light grey df ac">
134-
${repo.stars_count}
135-
{{svg "octicon-star" 16 "ml-2"}}
136-
</div>
133+
{{if not .DisableStars}}
134+
<div class="text light grey df ac">
135+
${repo.stars_count}
136+
{{svg "octicon-star" 16 "ml-2"}}
137+
</div>
138+
{{end}}
137139
</a>
138140
</li>
139141
</ul>

templates/user/profile.tmpl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,22 @@
8484
</div>
8585
<div class="ui eleven wide column">
8686
<div class="ui secondary stackable pointing tight menu">
87-
<a class='{{if and (ne .TabName "activity") (ne .TabName "following") (ne .TabName "followers") (ne .TabName "stars") (ne .TabName "projects")}}active{{end}} item' href="{{.Owner.HomeLink}}">
87+
<a class='{{if and (ne .TabName "activity") (ne .TabName "following") (ne .TabName "followers") (ne .TabName "stars") (ne .TabName "watching") (ne .TabName "projects")}}active{{end}} item' href="{{.Owner.HomeLink}}">
8888
{{svg "octicon-repo"}} {{.i18n.Tr "user.repositories"}}
8989
</a>
9090
<a class='{{if eq .TabName "activity"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=activity">
9191
{{svg "octicon-rss"}} {{.i18n.Tr "user.activity"}}
9292
</a>
93-
<a class='{{if eq .TabName "stars"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=stars">
94-
{{svg "octicon-star"}} {{.i18n.Tr "user.starred"}}
95-
<div class="ui label">{{.Owner.NumStars}}</div>
96-
</a>
93+
{{if not .DisableStars}}
94+
<a class='{{if eq .TabName "stars"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=stars">
95+
{{svg "octicon-star"}} {{.i18n.Tr "user.starred"}}
96+
<div class="ui label">{{.Owner.NumStars}}</div>
97+
</a>
98+
{{else}}
99+
<a class='{{if eq .TabName "watching"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=watching">
100+
{{svg "octicon-eye"}} {{.i18n.Tr "user.watched"}}
101+
</a>
102+
{{end}}
97103
<a class='{{if eq .TabName "following"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=following">
98104
{{svg "octicon-person"}} {{.i18n.Tr "user.following"}}
99105
<div class="ui label">{{.Owner.NumFollowing}}</div>

0 commit comments

Comments
 (0)