Skip to content

Commit 8156065

Browse files
authored
Merge branch 'master' into fix-13995-gitea-admin-user-delete---id-is-id
2 parents 4b61adf + 9e456b5 commit 8156065

File tree

14 files changed

+97
-38
lines changed

14 files changed

+97
-38
lines changed

.github/issue_template.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
<!--
44
1. Please speak English, this is the language all maintainers can speak and write.
5-
2. Please ask questions or configuration/deploy problems on our Discord
5+
2. Please ask questions or configuration/deploy problems on our Discord
66
server (https://discord.gg/gitea) or forum (https://discourse.gitea.io).
77
3. Please take a moment to check that your issue doesn't already exist.
8-
4. Please give all relevant information below for bug reports, because
8+
4. Make sure it's not mentioned in the FAQ (https://docs.gitea.io/en-us/faq)
9+
5. Please give all relevant information below for bug reports, because
910
incomplete details will be handled as an invalid report.
1011
-->
1112

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ PROJECT_BOARD_BASIC_KANBAN_TYPE = To Do, In Progress, Done
1717
PROJECT_BOARD_BUG_TRIAGE_TYPE = Needs Triage, High Priority, Low Priority, Closed
1818

1919
[repository]
20+
; Root path for storing all repository data. It must be an absolute path. By default it is stored in a sub-directory of `APP_DATA_PATH`.
2021
ROOT =
22+
; The script type this server supports. Usually this is `bash`, but some users report that only `sh` is available.
2123
SCRIPT_TYPE = bash
2224
; DETECTED_CHARSETS_ORDER tie-break order for detected charsets.
2325
; If the charsets have equal confidence, tie-breaking will be done by order in this list

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
4242

4343
## Repository (`repository`)
4444

45-
- `ROOT`: **~/gitea-repositories/**: Root path for storing all repository data. It must be
46-
an absolute path.
45+
- `ROOT`: **data/gitea-repositories/**: Root path for storing all repository data. It must be
46+
an absolute path. By default it is stored in a sub-directory of `APP_DATA_PATH`.
4747
- `SCRIPT_TYPE`: **bash**: The script type this server supports. Usually this is `bash`,
4848
but some users report that only `sh` is available.
4949
- `DETECTED_CHARSETS_ORDER`: **UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE, ISO-8859, windows-1252, ISO-8859, windows-1250, ISO-8859, ISO-8859, ISO-8859, windows-1253, ISO-8859, windows-1255, ISO-8859, windows-1251, windows-1256, KOI8-R, ISO-8859, windows-1254, Shift_JIS, GB18030, EUC-JP, EUC-KR, Big5, ISO-2022, ISO-2022, ISO-2022, IBM424_rtl, IBM424_ltr, IBM420_rtl, IBM420_ltr**: Tie-break order of detected charsets - if the detected charsets have equal confidence, charsets earlier in the list will be chosen in preference to those later. Adding `defaults` will place the unnamed charsets at that point.

docs/content/doc/help/faq.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ https://github.com/loganinak/MigrateGitlabToGogs
6464
- Windows: Environment variable `USERPROFILE`, else environment variables `HOMEDRIVE`+`HOMEPATH`
6565
- RepoRootPath
6666
- `ROOT` in `app.ini`
67-
- Else `%(HomeDir)/gitea-repositories`
67+
- Else `%(AppDataPath)/gitea-repositories`
6868
- INI (config file)
6969
- `-c` flag
7070
- Else `%(CustomPath)/conf/app.ini`

models/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ func (u *User) GetOwnedOrganizations() (err error) {
538538
}
539539

540540
// GetOrganizations returns paginated organizations that user belongs to.
541+
// TODO: does not respect All and show orgs you privately participate
541542
func (u *User) GetOrganizations(opts *SearchOrganizationsOptions) error {
542543
sess := x.NewSession()
543544
defer sess.Close()

modules/setting/repository.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"strings"
1111

1212
"code.gitea.io/gitea/modules/log"
13-
14-
"github.com/unknwon/com"
1513
)
1614

1715
// enumerates all the policy repository creating
@@ -249,19 +247,14 @@ var (
249247
)
250248

251249
func newRepository() {
252-
homeDir, err := com.HomeDir()
253-
if err != nil {
254-
log.Fatal("Failed to get home directory: %v", err)
255-
}
256-
homeDir = strings.ReplaceAll(homeDir, "\\", "/")
257-
250+
var err error
258251
// Determine and create root git repository path.
259252
sec := Cfg.Section("repository")
260253
Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
261254
Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
262255
Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1)
263256
Repository.DefaultBranch = sec.Key("DEFAULT_BRANCH").MustString(Repository.DefaultBranch)
264-
RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories"))
257+
RepoRootPath = sec.Key("ROOT").MustString(path.Join(AppDataPath, "gitea-repositories"))
265258
forcePathSeparator(RepoRootPath)
266259
if !filepath.IsAbs(RepoRootPath) {
267260
RepoRootPath = filepath.Join(AppWorkPath, RepoRootPath)

routers/api/v1/org/org.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,28 @@ import (
1717
"code.gitea.io/gitea/routers/api/v1/utils"
1818
)
1919

20-
func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) {
21-
if err := u.GetOrganizations(&models.SearchOrganizationsOptions{
22-
ListOptions: utils.GetListOptions(ctx),
23-
All: all,
24-
}); err != nil {
25-
ctx.Error(http.StatusInternalServerError, "GetOrganizations", err)
20+
func listUserOrgs(ctx *context.APIContext, u *models.User) {
21+
22+
listOptions := utils.GetListOptions(ctx)
23+
showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == u.ID)
24+
25+
orgs, err := models.GetOrgsByUserID(u.ID, showPrivate)
26+
if err != nil {
27+
ctx.Error(http.StatusInternalServerError, "GetOrgsByUserID", err)
2628
return
2729
}
30+
maxResults := len(orgs)
31+
32+
orgs = utils.PaginateUserSlice(orgs, listOptions.Page, listOptions.PageSize)
2833

29-
apiOrgs := make([]*api.Organization, len(u.Orgs))
30-
for i := range u.Orgs {
31-
apiOrgs[i] = convert.ToOrganization(u.Orgs[i])
34+
apiOrgs := make([]*api.Organization, len(orgs))
35+
for i := range orgs {
36+
apiOrgs[i] = convert.ToOrganization(orgs[i])
3237
}
38+
39+
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
40+
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
41+
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
3342
ctx.JSON(http.StatusOK, &apiOrgs)
3443
}
3544

@@ -53,7 +62,7 @@ func ListMyOrgs(ctx *context.APIContext) {
5362
// "200":
5463
// "$ref": "#/responses/OrganizationList"
5564

56-
listUserOrgs(ctx, ctx.User, true)
65+
listUserOrgs(ctx, ctx.User)
5766
}
5867

5968
// ListUserOrgs list user's orgs
@@ -85,7 +94,7 @@ func ListUserOrgs(ctx *context.APIContext) {
8594
if ctx.Written() {
8695
return
8796
}
88-
listUserOrgs(ctx, u, ctx.User != nil && (ctx.User.IsAdmin || ctx.User.ID == u.ID))
97+
listUserOrgs(ctx, u)
8998
}
9099

91100
// GetAll return list of all public organizations

routers/api/v1/utils/utils.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,22 @@ func GetListOptions(ctx *context.APIContext) models.ListOptions {
6666
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
6767
}
6868
}
69+
70+
// PaginateUserSlice cut a slice of Users as per pagination options
71+
// TODO: make it generic
72+
func PaginateUserSlice(items []*models.User, page, pageSize int) []*models.User {
73+
if page != 0 {
74+
page--
75+
}
76+
77+
if page*pageSize >= len(items) {
78+
return items[len(items):]
79+
}
80+
81+
items = items[page*pageSize:]
82+
83+
if len(items) > pageSize {
84+
return items[:pageSize]
85+
}
86+
return items
87+
}

services/pull/review.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,16 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
167167

168168
// Only fetch diff if comment is review comment
169169
if len(patch) == 0 && reviewID != 0 {
170+
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
171+
if err != nil {
172+
return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err)
173+
}
170174
if len(commitID) == 0 {
171-
commitID, err = gitRepo.GetRefCommitID(pr.GetGitRefName())
172-
if err != nil {
173-
return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err)
174-
}
175+
commitID = headCommitID
175176
}
176-
177177
patchBuf := new(bytes.Buffer)
178-
if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, commitID, git.RawDiffNormal, treePath, patchBuf); err != nil {
179-
return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", gitRepo.Path, pr.MergeBase, commitID, treePath, err)
178+
if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, headCommitID, git.RawDiffNormal, treePath, patchBuf); err != nil {
179+
return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", gitRepo.Path, pr.MergeBase, headCommitID, treePath, err)
180180
}
181181
patch = git.CutDiffAroundLine(patchBuf, int64((&models.Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
182182
}

services/release/release.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ func DeleteReleaseByID(id int64, doer *models.User, delTag bool) error {
152152
return fmt.Errorf("git tag -d: %v", err)
153153
}
154154

155+
notification.NotifyPushCommits(
156+
doer, repo,
157+
&repository.PushUpdateOptions{
158+
RefFullName: git.TagPrefix + rel.TagName,
159+
OldCommitID: rel.Sha1,
160+
NewCommitID: git.EmptySHA,
161+
}, repository.NewPushCommits())
162+
notification.NotifyDeleteRef(doer, repo, "tag", git.TagPrefix+rel.TagName)
163+
155164
if err := models.DeleteReleaseByID(id); err != nil {
156165
return fmt.Errorf("DeleteReleaseByID: %v", err)
157166
}

services/repository/push.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
9696
return fmt.Errorf("Old and new revisions are both %s", git.EmptySHA)
9797
}
9898
var commits = &repo_module.PushCommits{}
99-
if opts.IsTag() { // If is tag reference {
99+
if opts.IsTag() { // If is tag reference
100100
if pusher == nil || pusher.ID != opts.PusherID {
101101
var err error
102102
if pusher, err = models.GetUserByID(opts.PusherID); err != nil {
@@ -105,9 +105,25 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
105105
}
106106
tagName := opts.TagName()
107107
if opts.IsDelRef() {
108+
notification.NotifyPushCommits(
109+
pusher, repo,
110+
&repo_module.PushUpdateOptions{
111+
RefFullName: git.TagPrefix + tagName,
112+
OldCommitID: opts.OldCommitID,
113+
NewCommitID: git.EmptySHA,
114+
}, repo_module.NewPushCommits())
115+
108116
delTags = append(delTags, tagName)
109117
notification.NotifyDeleteRef(pusher, repo, "tag", opts.RefFullName)
110118
} else { // is new tag
119+
notification.NotifyPushCommits(
120+
pusher, repo,
121+
&repo_module.PushUpdateOptions{
122+
RefFullName: git.TagPrefix + tagName,
123+
OldCommitID: git.EmptySHA,
124+
NewCommitID: opts.NewCommitID,
125+
}, repo_module.NewPushCommits())
126+
111127
addTags = append(addTags, tagName)
112128
notification.NotifyCreateRef(pusher, repo, "tag", opts.RefFullName)
113129
}

snap/snapcraft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ architectures:
1818

1919
environment:
2020
GITEA_CUSTOM: "$SNAP_COMMON"
21-
GITEA_WORK_DIR: "$SNAP_DATA"
21+
GITEA_WORK_DIR: "$SNAP_COMMON"
2222
GIT_TEMPLATE_DIR: "$SNAP/usr/share/git-core/templates"
2323
GIT_EXEC_PATH: "$SNAP/usr/lib/git-core"
2424

templates/repo/settings/webhook/list.tmpl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@
4141
<div class="item">
4242
{{.Description | Str2html}}
4343
</div>
44-
<div class="ui divider"></div>
4544
{{range .Webhooks}}
46-
<div class="item p-2">
45+
<div class="item">
4746
{{if eq .LastStatus 1}}
48-
<span class="text green">{{svg "octicon-check"}}</span>
47+
<span class="text green mr-3">{{svg "octicon-check"}}</span>
4948
{{else if eq .LastStatus 2}}
50-
<span class="text red">{{svg "octicon-alert"}}</span>
49+
<span class="text red mr-3">{{svg "octicon-alert"}}</span>
5150
{{else}}
5251
<span class="text grey mr-3">{{svg "octicon-dot-fill"}}</span>
5352
{{end}}

web_src/less/_admin.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
.admin {
2+
&.hooks .list {
3+
> .item {
4+
&:not(:first-child) {
5+
border-top: 1px solid var(--color-secondary);
6+
padding: 1rem;
7+
margin: 15px -1rem -1rem;
8+
}
9+
}
10+
}
11+
212
.table.segment {
313
padding: 0;
414
font-size: 13px;

0 commit comments

Comments
 (0)