Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add star lists #27179

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make it work again
  • Loading branch information
JakobDev committed Mar 20, 2024
commit 6d869741daf775a7a324f2bd81ba615832a64a34
2 changes: 1 addition & 1 deletion models/repo/star.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func StarRepo(ctx context.Context, doer *user_model.User, repo *Repository, star
return err
}
// Delete the repo from all star lists of this user
if _, err := db.Exec(ctx, "DELETE FROM star_list_repos WHERE repo_id = ? AND star_list_id IN (SELECT id FROM star_list WHERE user_id = ?)", repoID, userID); err != nil {
if _, err := db.Exec(ctx, "DELETE FROM star_list_repos WHERE repo_id = ? AND star_list_id IN (SELECT id FROM star_list WHERE user_id = ?)", repo.ID, doer.ID); err != nil {
return err
}
}
Expand Down
12 changes: 11 additions & 1 deletion models/repo/star_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,17 @@ func (starList *StarList) AddRepo(ctx context.Context, repoID int64) error {
return nil
}

err = StarRepo(ctx, starList.UserID, repoID, true)
err = starList.LoadUser(ctx)
if err != nil {
return err
}

repo, err := GetRepositoryByID(ctx, repoID)
if err != nil {
return err
}

err = StarRepo(ctx, starList.User, repo, true)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions models/repo/star_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ func TestClearRepoStars(t *testing.T) {
func TestUnstarRepo(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())

const userID = 1
const repoID = 1
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})

assert.NoError(t, repo_model.StarRepo(db.DefaultContext, userID, repoID, false))
assert.NoError(t, repo_model.StarRepo(db.DefaultContext, user, repo, false))

assert.False(t, repo_model.IsStaring(db.DefaultContext, userID, repoID))
assert.False(t, repo_model.IsStaring(db.DefaultContext, user.ID, repo.ID))

// Check if the repo is removed from the star list
starList, err := repo_model.GetStarListByID(db.DefaultContext, 1)
assert.NoError(t, err)

assert.NoError(t, starList.LoadRepoIDs(db.DefaultContext))

assert.False(t, starList.ContainsRepoID(repoID))
assert.False(t, starList.ContainsRepoID(repo.ID))
}
4 changes: 2 additions & 2 deletions routers/api/v1/user/star_list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package user
Expand All @@ -11,10 +11,10 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
unit_model "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/convert"
)

Expand Down
5 changes: 4 additions & 1 deletion routers/web/repo/star_list.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package repo

import (
"slices"

repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/forms"
)

Expand Down
4 changes: 2 additions & 2 deletions routers/web/user/star_list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package user
Expand All @@ -9,10 +9,10 @@ import (

repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
shared_user "code.gitea.io/gitea/routers/web/shared/user"
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/forms"
)

Expand Down
2 changes: 1 addition & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ func registerRoutes(m *web.Route) {
m.Get("", user.UsernameSubRoute)
m.Get("/-/starlist/{name}", user.ShowStarList)
m.Post("/-/starlist_edit", web.Bind(forms.EditStarListForm{}), user.EditStarListPost)
}, context_service.UserAssignmentWeb())
}, context.UserAssignmentWeb())
m.Get("/attachments/{uuid}", repo.GetAttachment)
m.Get("/{username}", user.UsernameSubRoute)
m.Methods("GET, OPTIONS", "/attachments/{uuid}", optionsCorsHandler(), repo.GetAttachment)
Expand Down
1 change: 1 addition & 0 deletions services/context/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"strings"

repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
mc "code.gitea.io/gitea/modules/cache"
Expand Down
19 changes: 1 addition & 18 deletions templates/repo/header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,7 @@
{{end}}
{{template "repo/watch_unwatch" $}}
{{if not $.DisableStars}}
<form method="post" action="{{$.RepoLink}}/action/{{if $.IsStaringRepo}}un{{end}}star?redirect_to={{$.Link}}">
{{$.CsrfTokenHtml}}
<div class="ui labeled button" {{if not $.IsSigned}}data-tooltip-content="{{ctx.Locale.Tr "repo.star_guest_user"}}"{{end}}>
<button type="submit" class="ui compact small basic button"{{if not $.IsSigned}} disabled{{end}}>
{{if $.IsStaringRepo}}{{svg "octicon-star-fill"}}{{ctx.Locale.Tr "repo.unstar"}}{{else}}{{svg "octicon-star"}}{{ctx.Locale.Tr "repo.star"}}{{end}}
</button>
<a class="ui basic label {{if $.StarLists}}no-border-radius{{end}}" href="{{.Link}}/stars">
{{CountFmt .NumStars}}
</a>
{{if $.StarLists}}
<button type="button" class="ui compact small basic button show-modal no-border-radius-left no-margin-left" data-modal="#repo-star-list-modal">{{svg "octicon-pencil"}}</button>
{{end}}
</div>
</form>
{{template "repo/star_unstar" $}}
{{end}}
{{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
<div class="ui labeled button
Expand Down Expand Up @@ -242,7 +229,3 @@
</overflow-menu>
<div class="ui tabs divider"></div>
</div>

{{if not $.DisableStars}}
{{template "repo/starlistmodal" .}}
{{end}}
7 changes: 7 additions & 0 deletions templates/repo/star_unstar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@
<a hx-boost="false" class="ui basic label" href="{{$.RepoLink}}/stars">
{{CountFmt .Repository.NumStars}}
</a>
{{if $.StarLists}}
<button type="button" class="ui compact small basic button show-modal no-border-radius-left no-margin-left" data-modal="#repo-star-list-modal">{{svg "octicon-pencil"}}</button>
{{end}}
</div>

{{if not $.DisableStars}}
{{template "repo/starlistmodal" .}}
{{end}}
</form>
6 changes: 3 additions & 3 deletions templates/repo/starlistmodal.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="ui small modal" id="repo-star-list-modal">
<div class="header">
{{.locale.Tr "starlist.list_header"}}
{{ctx.Locale.Tr "starlist.list_header"}}
</div>
<div class="content">
<form class="ui form" action="{{$.RepoLink}}/starlistedit" method="POST">
Expand All @@ -18,11 +18,11 @@
<div class="text right actions">
<button class="ui small basic cancel button">
{{svg "octicon-x"}}
{{.locale.Tr "cancel"}}
{{ctx.Locale.Tr "cancel"}}
</button>
<button class="ui primary small approve button">
{{svg "fontawesome-save"}}
{{.locale.Tr "save"}}
{{ctx.Locale.Tr "save"}}
</button>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion templates/swagger/v1_json.tmpl

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

18 changes: 9 additions & 9 deletions templates/user/starlist/edit.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="ui small modal" id="edit-star-list-modal">
<div class="header">
{{if .CurrentStarList}}
{{.locale.Tr "starlist.edit_header"}}
{{ctx.Locale.Tr "starlist.edit_header"}}
{{else}}
{{.locale.Tr "starlist.add_header"}}
{{ctx.Locale.Tr "starlist.add_header"}}
{{end}}
</div>
<div class="content">
Expand All @@ -20,30 +20,30 @@
{{end}}

<div class="field">
<label for="name">{{.locale.Tr "starlist.name_label"}}</label>
<input id="name" name="name" placeholder="{{.locale.Tr "starlist.name_placeholder"}}" {{if .CurrentStarList}}value="{{.CurrentStarList.Name}}"{{end}} maxlength="50" required>
<label for="name">{{ctx.Locale.Tr "starlist.name_label"}}</label>
<input id="name" name="name" placeholder="{{ctx.Locale.Tr "starlist.name_placeholder"}}" {{if .CurrentStarList}}value="{{.CurrentStarList.Name}}"{{end}} maxlength="50" required>
</div>

<div class="field">
<label for="description">{{.locale.Tr "starlist.description_label"}}</label>
<textarea id="description" name="description" rows="2" placeholder="{{.locale.Tr "starlist.description_placeholder"}}" maxlength="255">{{if .CurrentStarList}}{{.CurrentStarList.Description}}{{end}}</textarea>
<label for="description">{{ctx.Locale.Tr "starlist.description_label"}}</label>
<textarea id="description" name="description" rows="2" placeholder="{{ctx.Locale.Tr "starlist.description_placeholder"}}" maxlength="255">{{if .CurrentStarList}}{{.CurrentStarList.Description}}{{end}}</textarea>
</div>

<div class="field">
<div class="ui checkbox">
<label for="private">{{.locale.Tr "starlist.private"}}</label>
<label for="private">{{ctx.Locale.Tr "starlist.private"}}</label>
<input name="private" type="checkbox" {{if .CurrentStarList}}{{if .CurrentStarList.IsPrivate}}checked{{end}}{{end}}>
</div>
</div>

<div class="text right actions">
<button class="ui small basic cancel button">
{{svg "octicon-x"}}
{{.locale.Tr "cancel"}}
{{ctx.Locale.Tr "cancel"}}
</button>
<button class="ui primary small approve button">
{{svg "fontawesome-save"}}
{{if .CurrentStarList}}{{.locale.Tr "save"}}{{else}}{{.locale.Tr "add"}}{{end}}
{{if .CurrentStarList}}{{ctx.Locale.Tr "save"}}{{else}}{{ctx.Locale.Tr "add"}}{{end}}
</button>
</div>
</form>
Expand Down
12 changes: 6 additions & 6 deletions templates/user/starlist/list.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="star-list-box">
<h4 class="ui top attached header">
{{.locale.Tr "starlist.list_header"}}
{{ctx.Locale.Tr "starlist.list_header"}}
{{if .ContextUser.IsSameUser .SignedUser}}
<div class="ui right">
<button class="ui tiny button green show-modal" data-modal="#edit-star-list-modal">{{.locale.Tr "add"}}</button>
<button class="ui tiny button green show-modal" data-modal="#edit-star-list-modal">{{ctx.Locale.Tr "add"}}</button>
</div>
{{end}}
</h4>
Expand All @@ -16,22 +16,22 @@
<div class="flex-item-title">
{{.Name}}
{{if .IsPrivate}}
<span class="ui basic label">{{$.locale.Tr "repo.desc.private"}}</span>
<span class="ui basic label">{{$.ctx.Locale.Tr "repo.desc.private"}}</span>
{{end}}
</div>
<div class="flex-item-trailing">
{{if eq .RepositoryCount 1}}
<span class="text grey flex-text-inline">{{$.locale.Tr "repository_count_1"}}</span>
<span class="text grey flex-text-inline">{{$.ctx.Locale.Tr "repository_count_1"}}</span>
{{else}}
<span class="text grey flex-text-inline">{{$.locale.Tr "repository_count_n" .RepositoryCount}}</span>
<span class="text grey flex-text-inline">{{$.ctx.Locale.Tr "repository_count_n" .RepositoryCount}}</span>
{{end}}
</div>
</a>
</div>
{{end}}
</div>
{{else}}
{{.locale.Tr "starlist.no_star_lists_text"}}
{{ctx.Locale.Tr "starlist.no_star_lists_text"}}
{{end}}
</div>
</div>
14 changes: 7 additions & 7 deletions templates/user/starlist/repos.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
</div>
{{if .ContextUser.IsSameUser .SignedUser}}
<div>
<button class="ui button green show-modal" data-modal="#edit-star-list-modal">{{.locale.Tr "edit"}}</button>
<button class="ui button red show-modal" data-modal="#delete-star-list-modal">{{.locale.Tr "remove"}}</button>
<button class="ui button green show-modal" data-modal="#edit-star-list-modal">{{ctx.Locale.Tr "edit"}}</button>
<button class="ui button red show-modal" data-modal="#delete-star-list-modal">{{ctx.Locale.Tr "remove"}}</button>
</div>
{{end}}
</div>

{{template "explore/repo_search" .}}
{{template "shared/repo_search" .}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
</div>
Expand All @@ -39,11 +39,11 @@

<div class="ui small modal" id="delete-star-list-modal">
<div class="header">
{{.locale.Tr "starlist.delete_header"}}
{{ctx.Locale.Tr "starlist.delete_header"}}
</div>
<div class="content">
<div class="ui warning message">
{{.locale.Tr "repo.settings.delete_notices_1" | Safe}}
{{ctx.Locale.Tr "repo.settings.delete_notices_1" | SafeHTML}}
</div>
<form class="ui form" action="{{.EditStarListURL}}" method="post">
{{.CsrfTokenHtml}}
Expand All @@ -53,8 +53,8 @@
<input name="action" type="hidden" value="delete">

<div class="text right actions">
<button class="ui cancel button">{{.locale.Tr "cancel"}}</button>
<button class="ui red button">{{.locale.Tr "remove"}}</button>
<button class="ui cancel button">{{ctx.Locale.Tr "cancel"}}</button>
<button class="ui red button">{{ctx.Locale.Tr "remove"}}</button>
</div>
</form>
</div>
Expand Down
Loading