From 9d184f13e4362627ddc7cdb1f02207d461a0c0d4 Mon Sep 17 00:00:00 2001 From: Kyle D Date: Thu, 11 Feb 2021 00:07:50 -0700 Subject: [PATCH 1/3] Add config option to disable stars --- modules/context/context.go | 1 + modules/setting/repository.go | 2 ++ modules/structs/settings.go | 7 ++++--- routers/api/v1/settings/settings.go | 7 ++++--- templates/base/head_navbar.tmpl | 10 ++++++---- templates/explore/repo_list.tmpl | 4 +++- templates/explore/repo_search.tmpl | 2 ++ templates/repo/header.tmpl | 24 +++++++++++++----------- templates/swagger/v1_json.tmpl | 4 ++++ templates/user/dashboard/repolist.tmpl | 10 ++++++---- 10 files changed, 45 insertions(+), 26 deletions(-) diff --git a/modules/context/context.go b/modules/context/context.go index ea267dfb3fc64..2ef2d464bebcf 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -712,6 +712,7 @@ func Contexter() func(next http.Handler) http.Handler { ctx.Data["EnableSwagger"] = setting.API.EnableSwagger ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations + ctx.Data["DisableStars"] = setting.Repository.DisableStars ctx.Data["ManifestData"] = setting.ManifestData diff --git a/modules/setting/repository.go b/modules/setting/repository.go index 139512bf008c1..966ff9e888bec 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -43,6 +43,7 @@ var ( PrefixArchiveFiles bool DisableMirrors bool DisableMigrations bool + DisableStars bool `ini:"DISABLE_STARS"` DefaultBranch string AllowAdoptionOfUnadoptedRepositories bool AllowDeleteOfUnadoptedRepositories bool @@ -154,6 +155,7 @@ var ( PrefixArchiveFiles: true, DisableMirrors: false, DisableMigrations: false, + DisableStars: false, DefaultBranch: "master", // Repository editor settings diff --git a/modules/structs/settings.go b/modules/structs/settings.go index e15c750356f68..abeb0f99f430e 100644 --- a/modules/structs/settings.go +++ b/modules/structs/settings.go @@ -6,9 +6,10 @@ package structs // GeneralRepoSettings contains global repository settings exposed by API type GeneralRepoSettings struct { - MirrorsDisabled bool `json:"mirrors_disabled"` - HTTPGitDisabled bool `json:"http_git_disabled"` - MigrationsDisabled bool `json:"migrations_disabled"` + MirrorsDisabled bool `json:"mirrors_disabled"` + HTTPGitDisabled bool `json:"http_git_disabled"` + MigrationsDisabled bool `json:"migrations_disabled"` + StarsDisabled bool `json:"stars_disabled"` TimeTrackingDisabled bool `json:"time_tracking_disabled"` LFSDisabled bool `json:"lfs_disabled"` } diff --git a/routers/api/v1/settings/settings.go b/routers/api/v1/settings/settings.go index cfb059a3acce8..187075ba3e442 100644 --- a/routers/api/v1/settings/settings.go +++ b/routers/api/v1/settings/settings.go @@ -57,9 +57,10 @@ func GetGeneralRepoSettings(ctx *context.APIContext) { // "200": // "$ref": "#/responses/GeneralRepoSettings" ctx.JSON(http.StatusOK, api.GeneralRepoSettings{ - MirrorsDisabled: setting.Repository.DisableMirrors, - HTTPGitDisabled: setting.Repository.DisableHTTPGit, - MigrationsDisabled: setting.Repository.DisableMigrations, + MirrorsDisabled: setting.Repository.DisableMirrors, + HTTPGitDisabled: setting.Repository.DisableHTTPGit, + MigrationsDisabled: setting.Repository.DisableMigrations, + StarsDisabled: setting.Repository.DisableStars, TimeTrackingDisabled: !setting.Service.EnableTimetracking, LFSDisabled: !setting.LFS.StartServer, }) diff --git a/templates/base/head_navbar.tmpl b/templates/base/head_navbar.tmpl index efab76f33c0f4..a7437c379b187 100644 --- a/templates/base/head_navbar.tmpl +++ b/templates/base/head_navbar.tmpl @@ -157,10 +157,12 @@ {{svg "octicon-person"}} {{.i18n.Tr "your_profile"}} - - {{svg "octicon-star"}} - {{.i18n.Tr "your_starred"}} - + {{if not .DisableStars}} + + {{svg "octicon-star"}} + {{.i18n.Tr "your_starred"}} + + {{end}} {{svg "octicon-tools"}} {{.i18n.Tr "your_settings"}} diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 91dc3d8bf40a7..4ff48b60761d8 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -42,7 +42,9 @@ {{if .PrimaryLanguage }} {{ .PrimaryLanguage.Language }} {{end}} - {{svg "octicon-star" 16 "mr-3"}}{{.NumStars}} + {{if not $.DisableStars}} + {{svg "octicon-star" 16 "mr-3"}}{{.NumStars}} + {{end}} {{svg "octicon-git-branch" 16 "mr-3"}}{{.NumForks}} diff --git a/templates/explore/repo_search.tmpl b/templates/explore/repo_search.tmpl index 53c5156dc9a8b..e75249a4f11a1 100644 --- a/templates/explore/repo_search.tmpl +++ b/templates/explore/repo_search.tmpl @@ -12,8 +12,10 @@ {{.i18n.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}} {{.i18n.Tr "repo.issues.filter_sort.recentupdate"}} {{.i18n.Tr "repo.issues.filter_sort.leastupdate"}} + {{if not .DisableStars}} {{.i18n.Tr "repo.issues.filter_sort.moststars"}} {{.i18n.Tr "repo.issues.filter_sort.feweststars"}} + {{end}} {{.i18n.Tr "repo.issues.filter_sort.mostforks"}} {{.i18n.Tr "repo.issues.filter_sort.fewestforks"}} diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 31bcd5c48a8d7..99eec3d946fd3 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -53,17 +53,19 @@ -
- {{$.CsrfTokenHtml}} -
- - - {{CountFmt .NumStars}} - -
-
+ {{if not $.DisableStars}} +
+ {{$.CsrfTokenHtml}} +
+ + + {{CountFmt .NumStars}} + +
+
+ {{end}} {{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 4a97650e56a73..1c24c99ed2be1 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -14113,6 +14113,10 @@ "type": "boolean", "x-go-name": "MirrorsDisabled" }, + "stars_disabled": { + "type": "boolean", + "x-go-name": "StarsDisabled" + }, "time_tracking_disabled": { "type": "boolean", "x-go-name": "TimeTrackingDisabled" diff --git a/templates/user/dashboard/repolist.tmpl b/templates/user/dashboard/repolist.tmpl index 9115c62ecdf92..c57d42539ef2f 100644 --- a/templates/user/dashboard/repolist.tmpl +++ b/templates/user/dashboard/repolist.tmpl @@ -130,10 +130,12 @@ {{svg "octicon-archive" 16 "ml-2"}}
-
- ${repo.stars_count} - {{svg "octicon-star" 16 "ml-2"}} -
+ {{if not .DisableStars}} +
+ ${repo.stars_count} + {{svg "octicon-star" 16 "ml-2"}} +
+ {{end}}
From 882a2363915c72791f420ef71da7220d3bfa29dd Mon Sep 17 00:00:00 2001 From: Kyle D Date: Thu, 11 Feb 2021 02:36:08 -0700 Subject: [PATCH 2/3] Replace "stars" with watched in user profile --- models/repo_list.go | 6 ++++++ options/locale/locale_en-US.ini | 1 + routers/user/profile.go | 21 +++++++++++++++++++++ templates/user/profile.tmpl | 16 +++++++++++----- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index de3562a2abb6e..3359181ee93ec 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -142,6 +142,7 @@ type SearchRepoOptions struct { OrderBy SearchOrderBy Private bool // Include private repositories in results StarredByID int64 + WatchedByID int64 AllPublic bool // Include also all public repositories of users and public organisations AllLimited bool // Include also all public repositories of limited organisations // None -> include public and private @@ -240,6 +241,11 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { cond = cond.And(builder.In("id", builder.Select("repo_id").From("star").Where(builder.Eq{"uid": opts.StarredByID}))) } + // Restrict to watched repositories + if opts.WatchedByID > 0 { + cond = cond.And(builder.In("id", builder.Select("repo_id").From("watch").Where(builder.Eq{"user_id": opts.WatchedByID}))) + } + // Restrict repositories to those the OwnerID owns or contributes to as per opts.Collaborate if opts.OwnerID > 0 { var accessCond = builder.NewCond() diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 2690303253343..50ee3bd92a05d 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -412,6 +412,7 @@ repositories = Repositories activity = Public Activity followers = Followers starred = Starred Repositories +watched = Watched Repositories projects = Projects following = Following follow = Follow diff --git a/routers/user/profile.go b/routers/user/profile.go index e19407baa78cf..7c720cd87612d 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -238,6 +238,27 @@ func Profile(ctx *context.Context) { ctx.ServerError("GetProjects", err) return } + case "watching": + repos, count, err = models.SearchRepository(&models.SearchRepoOptions{ + ListOptions: models.ListOptions{ + PageSize: setting.UI.User.RepoPagingNum, + Page: page, + }, + Actor: ctx.User, + Keyword: keyword, + OrderBy: orderBy, + Private: ctx.IsSigned, + WatchedByID: ctxUser.ID, + Collaborate: util.OptionalBoolFalse, + TopicOnly: topicOnly, + IncludeDescription: setting.UI.SearchRepoDescription, + }) + if err != nil { + ctx.ServerError("SearchRepository", err) + return + } + + total = int(count) default: repos, count, err = models.SearchRepository(&models.SearchRepoOptions{ ListOptions: models.ListOptions{ diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index ddad4c46c3511..18f3c9f6ddecd 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -84,16 +84,22 @@