Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions routers/api/v1/repo/star.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"

repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/context"
Expand Down Expand Up @@ -44,6 +45,13 @@ func ListStargazers(ctx *context.APIContext) {
// "$ref": "#/responses/UserList"
// "404":
// "$ref": "#/responses/notFound"
// "403":
// "$ref": "#/responses/forbidden"

if setting.Repository.DisableStars {
ctx.Error(http.StatusForbidden, "StarsDisabled", "Stars are disabled.")
return
}

stargazers, err := repo_model.GetStargazers(ctx, ctx.Repo.Repository, utils.GetListOptions(ctx))
if err != nil {
Expand Down
34 changes: 34 additions & 0 deletions routers/api/v1/user/star.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/context"
Expand Down Expand Up @@ -66,6 +67,13 @@ func GetStarredRepos(ctx *context.APIContext) {
// "$ref": "#/responses/RepositoryList"
// "404":
// "$ref": "#/responses/notFound"
// "403":
// "$ref": "#/responses/forbidden"

if setting.Repository.DisableStars {
ctx.Error(http.StatusForbidden, "StarsDisabled", "Stars are disabled.")
return
}

private := ctx.ContextUser.ID == ctx.Doer.ID
repos, err := getStarredRepos(ctx, ctx.ContextUser, private)
Expand Down Expand Up @@ -97,6 +105,13 @@ func GetMyStarredRepos(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/RepositoryList"
// "403":
// "$ref": "#/responses/forbidden"

if setting.Repository.DisableStars {
ctx.Error(http.StatusForbidden, "StarsDisabled", "Stars are disabled.")
return
}

repos, err := getStarredRepos(ctx, ctx.Doer, true)
if err != nil {
Expand Down Expand Up @@ -128,6 +143,13 @@ func IsStarring(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
// "403":
// "$ref": "#/responses/forbidden"

if setting.Repository.DisableStars {
ctx.Error(http.StatusForbidden, "StarsDisabled", "Stars are disabled.")
return
}

if repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) {
ctx.Status(http.StatusNoContent)
Expand Down Expand Up @@ -160,6 +182,11 @@ func Star(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"

if setting.Repository.DisableStars {
ctx.Error(http.StatusForbidden, "StarsDisabled", "Stars are disabled.")
return
}

err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, true)
if err != nil {
if errors.Is(err, user_model.ErrBlockedUser) {
Expand Down Expand Up @@ -193,6 +220,13 @@ func Unstar(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
// "403":
// "$ref": "#/responses/forbidden"

if setting.Repository.DisableStars {
ctx.Error(http.StatusForbidden, "StarsDisabled", "Stars are disabled.")
return
}

err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
if err != nil {
Expand Down
17 changes: 12 additions & 5 deletions routers/web/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,13 @@ func Action(ctx *context.Context) {
err = repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, true)
case "unwatch":
err = repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
case "star":
err = repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, true)
case "unstar":
err = repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
case "star", "unstar":
if setting.Repository.DisableStars {
err = errors.New("stars are disabled")
} else {
err = repo_model.StarRepo(ctx, ctx.Doer,
ctx.Repo.Repository, ctx.PathParam("action") == "star")
}
case "accept_transfer":
acceptTransfer(ctx)
return
Expand All @@ -377,7 +380,11 @@ func Action(ctx *context.Context) {
case "watch", "unwatch":
ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
case "star", "unstar":
ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
if setting.Repository.DisableStars {
ctx.Data["IsStaringRepo"] = false
} else {
ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
}
}

// see the `hx-trigger="refreshUserCards ..."` comments in tmpl
Expand Down
4 changes: 4 additions & 0 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ func Watchers(ctx *context.Context) {

// Stars render repository's starred users
func Stars(ctx *context.Context) {
if setting.Repository.DisableStars {
ctx.NotFound("Stars disabled", nil)
return
}
ctx.Data["Title"] = ctx.Tr("repo.stargazers")
ctx.Data["CardsTitle"] = ctx.Tr("repo.stargazers")
RenderUserCards(ctx, ctx.Repo.Repository.NumStars, func(opts db.ListOptions) ([]*user_model.User, error) {
Expand Down
15 changes: 15 additions & 0 deletions templates/swagger/v1_json.tmpl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.