Skip to content

Commit f39a9a3

Browse files
committed
Merge remote-tracking branch 'main/master' into branch-view-add-download-button
2 parents 95bceca + a19138c commit f39a9a3

File tree

15 files changed

+44
-40
lines changed

15 files changed

+44
-40
lines changed

docs/content/doc/usage/reverse-proxies.en-us.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ In case you already have a site, and you want Gitea to share the domain name, yo
7171
<Proxy *>
7272
Order allow,deny
7373
Allow from all
74-
AllowEncodedSlashes NoDecode
7574
</Proxy>
76-
77-
ProxyPass /git http://localhost:3000 nocanon # Note: no trailing slash after either /git or port
78-
ProxyPassReverse /git http://localhost:3000 # Note: no trailing slash after either /git or port
75+
AllowEncodedSlashes NoDecode
76+
# Note: no trailing slash after either /git or port
77+
ProxyPass /git http://localhost:3000 nocanon
78+
ProxyPassReverse /git http://localhost:3000
7979
</VirtualHost>
8080
```
8181

docs/content/doc/usage/reverse-proxies.zh-cn.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ server {
7272
<Proxy *>
7373
Order allow,deny
7474
Allow from all
75-
AllowEncodedSlashes NoDecode
7675
</Proxy>
77-
78-
ProxyPass /git http://localhost:3000 nocanon # Note: no trailing slash after either /git or port
79-
ProxyPassReverse /git http://localhost:3000 # Note: no trailing slash after either /git or port
76+
AllowEncodedSlashes NoDecode
77+
# Note: no trailing slash after either /git or port
78+
ProxyPass /git http://localhost:3000 nocanon
79+
ProxyPassReverse /git http://localhost:3000
8080
</VirtualHost>
8181
```
8282

models/user.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ func (u *User) UpdateTheme(themeName string) error {
204204
return UpdateUserCols(u, "theme")
205205
}
206206

207-
// getEmail returns an noreply email, if the user has set to keep his
207+
// GetEmail returns an noreply email, if the user has set to keep his
208208
// email address private, otherwise the primary email address.
209-
func (u *User) getEmail() string {
209+
func (u *User) GetEmail() string {
210210
if u.KeepEmailPrivate {
211211
return fmt.Sprintf("%s@%s", u.LowerName, setting.Service.NoReplyAddress)
212212
}
@@ -219,7 +219,7 @@ func (u *User) APIFormat() *api.User {
219219
ID: u.ID,
220220
UserName: u.Name,
221221
FullName: u.FullName,
222-
Email: u.getEmail(),
222+
Email: u.GetEmail(),
223223
AvatarURL: u.AvatarLink(),
224224
Language: u.Language,
225225
IsAdmin: u.IsAdmin,
@@ -434,7 +434,7 @@ func (u *User) GetFollowing(page int) ([]*User, error) {
434434
func (u *User) NewGitSig() *git.Signature {
435435
return &git.Signature{
436436
Name: u.GitName(),
437-
Email: u.getEmail(),
437+
Email: u.GetEmail(),
438438
When: time.Now(),
439439
}
440440
}
@@ -783,6 +783,7 @@ var (
783783
"robots.txt",
784784
".",
785785
"..",
786+
".well-known",
786787
}
787788
reservedUserPatterns = []string{"*.keys", "*.gpg"}
788789
)

routers/api/v1/admin/user.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
9191
if form.SendNotify && setting.MailService != nil {
9292
models.SendRegisterNotifyMail(ctx.Context.Context, u)
9393
}
94-
95-
ctx.JSON(201, u.APIFormat())
94+
ctx.JSON(201, convert.ToUser(u, ctx.IsSigned, ctx.User.IsAdmin))
9695
}
9796

9897
// EditUser api for modifying a user's information
@@ -181,7 +180,7 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
181180
}
182181
log.Trace("Account profile updated by admin (%s): %s", ctx.User.Name, u.Name)
183182

184-
ctx.JSON(200, u.APIFormat())
183+
ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User.IsAdmin))
185184
}
186185

187186
// DeleteUser api for deleting a user
@@ -326,7 +325,7 @@ func GetAllUsers(ctx *context.APIContext) {
326325

327326
results := make([]*api.User, len(users))
328327
for i := range users {
329-
results[i] = convert.ToUser(users[i], ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
328+
results[i] = convert.ToUser(users[i], ctx.IsSigned, ctx.User.IsAdmin)
330329
}
331330

332331
ctx.JSON(200, &results)

routers/api/v1/convert/convert.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func ToTeam(team *models.Team) *api.Team {
229229
}
230230

231231
// ToUser convert models.User to api.User
232-
func ToUser(user *models.User, signed, admin bool) *api.User {
232+
func ToUser(user *models.User, signed, authed bool) *api.User {
233233
result := &api.User{
234234
ID: user.ID,
235235
UserName: user.Name,
@@ -239,7 +239,12 @@ func ToUser(user *models.User, signed, admin bool) *api.User {
239239
LastLogin: user.LastLoginUnix.AsTime(),
240240
Created: user.CreatedUnix.AsTime(),
241241
}
242-
if signed && (!user.KeepEmailPrivate || admin) {
242+
// hide primary email if API caller isn't user itself or an admin
243+
if !signed {
244+
result.Email = ""
245+
} else if user.KeepEmailPrivate && !authed {
246+
result.Email = user.GetEmail()
247+
} else {
243248
result.Email = user.Email
244249
}
245250
return result

routers/api/v1/org/member.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/modules/context"
1414
"code.gitea.io/gitea/modules/setting"
15+
"code.gitea.io/gitea/routers/api/v1/convert"
1516
"code.gitea.io/gitea/routers/api/v1/user"
1617
)
1718

@@ -46,7 +47,7 @@ func listMembers(ctx *context.APIContext, publicOnly bool) {
4647

4748
apiMembers := make([]*api.User, len(members))
4849
for i, member := range members {
49-
apiMembers[i] = member.APIFormat()
50+
apiMembers[i] = convert.ToUser(member, ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
5051
}
5152
ctx.JSON(200, apiMembers)
5253
}

routers/api/v1/org/team.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func GetTeamMembers(ctx *context.APIContext) {
257257
}
258258
members := make([]*api.User, len(team.Members))
259259
for i, member := range team.Members {
260-
members[i] = member.APIFormat()
260+
members[i] = convert.ToUser(member, ctx.IsSigned, ctx.User.IsAdmin)
261261
}
262262
ctx.JSON(200, members)
263263
}
@@ -288,7 +288,7 @@ func GetTeamMember(ctx *context.APIContext) {
288288
if ctx.Written() {
289289
return
290290
}
291-
ctx.JSON(200, u.APIFormat())
291+
ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User.IsAdmin))
292292
}
293293

294294
// AddTeamMember api for add a member to a team

routers/api/v1/repo/collaborators.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/modules/context"
1313

1414
api "code.gitea.io/gitea/modules/structs"
15+
"code.gitea.io/gitea/routers/api/v1/convert"
1516
)
1617

1718
// ListCollaborators list a repository's collaborators
@@ -42,7 +43,7 @@ func ListCollaborators(ctx *context.APIContext) {
4243
}
4344
users := make([]*api.User, len(collaborators))
4445
for i, collaborator := range collaborators {
45-
users[i] = collaborator.APIFormat()
46+
users[i] = convert.ToUser(collaborator.User, ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
4647
}
4748
ctx.JSON(200, users)
4849
}

routers/api/v1/repo/hook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ func TestHook(ctx *context.APIContext) {
130130
convert.ToCommit(ctx.Repo.Repository, ctx.Repo.Commit),
131131
},
132132
Repo: ctx.Repo.Repository.APIFormat(models.AccessModeNone),
133-
Pusher: ctx.User.APIFormat(),
134-
Sender: ctx.User.APIFormat(),
133+
Pusher: convert.ToUser(ctx.User, ctx.IsSigned, false),
134+
Sender: convert.ToUser(ctx.User, ctx.IsSigned, false),
135135
}); err != nil {
136136
ctx.Error(500, "PrepareWebhook: ", err)
137137
return

routers/api/v1/repo/star.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"code.gitea.io/gitea/modules/context"
99

1010
api "code.gitea.io/gitea/modules/structs"
11+
"code.gitea.io/gitea/routers/api/v1/convert"
1112
)
1213

1314
// ListStargazers list a repository's stargazers
@@ -38,7 +39,7 @@ func ListStargazers(ctx *context.APIContext) {
3839
}
3940
users := make([]*api.User, len(stargazers))
4041
for i, stargazer := range stargazers {
41-
users[i] = stargazer.APIFormat()
42+
users[i] = convert.ToUser(stargazer, ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
4243
}
4344
ctx.JSON(200, users)
4445
}

routers/api/v1/repo/subscriber.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"code.gitea.io/gitea/modules/context"
99

1010
api "code.gitea.io/gitea/modules/structs"
11+
"code.gitea.io/gitea/routers/api/v1/convert"
1112
)
1213

1314
// ListSubscribers list a repo's subscribers (i.e. watchers)
@@ -38,7 +39,7 @@ func ListSubscribers(ctx *context.APIContext) {
3839
}
3940
users := make([]*api.User, len(subscribers))
4041
for i, subscriber := range subscribers {
41-
users[i] = subscriber.APIFormat()
42+
users[i] = convert.ToUser(subscriber, ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
4243
}
4344
ctx.JSON(200, users)
4445
}

routers/api/v1/user/follower.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import (
99

1010
"code.gitea.io/gitea/models"
1111
"code.gitea.io/gitea/modules/context"
12+
"code.gitea.io/gitea/routers/api/v1/convert"
1213
)
1314

1415
func responseAPIUsers(ctx *context.APIContext, users []*models.User) {
1516
apiUsers := make([]*api.User, len(users))
1617
for i := range users {
17-
apiUsers[i] = users[i].APIFormat()
18+
apiUsers[i] = convert.ToUser(users[i], ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
1819
}
1920
ctx.JSON(200, &apiUsers)
2021
}

routers/api/v1/user/key.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ func appendPrivateInformation(apiKey *api.PublicKey, key *models.PublicKey, defa
2222
apiKey.KeyType = "user"
2323

2424
if defaultUser.ID == key.OwnerID {
25-
apiKey.Owner = defaultUser.APIFormat()
25+
apiKey.Owner = convert.ToUser(defaultUser, true, true)
2626
} else {
2727
user, err := models.GetUserByID(key.OwnerID)
2828
if err != nil {
2929
return apiKey, err
3030
}
31-
apiKey.Owner = user.APIFormat()
31+
apiKey.Owner = convert.ToUser(user, true, true)
3232
}
3333
} else {
3434
apiKey.KeyType = "unknown"

routers/api/v1/user/user.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,7 @@ func GetInfo(ctx *context.APIContext) {
104104
return
105105
}
106106

107-
// Hide user e-mail when API caller isn't signed in.
108-
if !ctx.IsSigned {
109-
u.Email = ""
110-
}
111-
ctx.JSON(200, u.APIFormat())
107+
ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User.ID == u.ID || ctx.User.IsAdmin))
112108
}
113109

114110
// GetAuthenticatedUser get current user's information
@@ -121,7 +117,7 @@ func GetAuthenticatedUser(ctx *context.APIContext) {
121117
// responses:
122118
// "200":
123119
// "$ref": "#/responses/User"
124-
ctx.JSON(200, ctx.User.APIFormat())
120+
ctx.JSON(200, convert.ToUser(ctx.User, ctx.IsSigned, ctx.User != nil))
125121
}
126122

127123
// GetUserHeatmapData is the handler to get a users heatmap

templates/repo/branch/list.tmpl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
</div>
6969
<div class="bar-group">
7070
<div class="count count-ahead">{{.CommitsAhead}}</div>
71-
<div class="bar bar-ahead" style="width: {{percentage .CommitsAhead .CommitsBehind .CommitsAhead}}%"></div>
71+
<div class="bar bar-ahead" style="width: {{percentage .CommitsAhead .CommitsBehind .CommitsAhead}}%"></div>
7272
</div>
7373
</div>
7474
{{end}}
@@ -100,11 +100,9 @@
100100
</div>
101101
</div>
102102
{{if and $.IsWriter (not $.IsMirror)}}
103-
{{if .IsProtected}}
104-
<i class="octicon octicon-shield"></i>
105-
{{else if .IsDeleted}}
103+
{{if and .IsDeleted (not .IsProtected)}}
106104
<a class="ui basic jump button icon poping up undo-button" href data-url="{{$.Link}}/restore?branch_id={{.DeletedBranch.ID | urlquery}}&name={{.DeletedBranch.Name | urlquery}}" data-content="{{$.i18n.Tr "repo.branch.restore" (.Name | EscapePound)}}" data-variation="tiny inverted" data-position="top right"><i class="octicon octicon-reply text blue"></i></a>
107-
{{else}}
105+
{{else if (not .IsProtected)}}
108106
<a class="ui basic jump button icon poping up delete-branch-button" href data-url="{{$.Link}}/delete?name={{.Name | urlquery}}" data-content="{{$.i18n.Tr "repo.branch.delete" (.Name | EscapePound)}}" data-variation="tiny inverted" data-position="top right" data-name="{{.Name}}"><i class="trash icon text red"></i></a>
109107
{{end}}
110108
{{end}}

0 commit comments

Comments
 (0)