mirror of
https://github.com/go-gitea/gitea
synced 2024-06-01 19:06:52 +02:00
Compare commits
4 Commits
32714339f3
...
f1296a94fc
Author | SHA1 | Date | |
---|---|---|---|
|
f1296a94fc | ||
|
821d2fc2a3 | ||
|
b3090b588f | ||
|
5644010c84 |
|
@ -65,7 +65,19 @@ func (opts *SearchUserOptions) toSearchQueryBase(ctx context.Context) *xorm.Sess
|
|||
builder.Like{"LOWER(full_name)", lowerKeyword},
|
||||
)
|
||||
if opts.SearchByEmail {
|
||||
keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword})
|
||||
var emailCond builder.Cond
|
||||
emailCond = builder.Like{"LOWER(email)", lowerKeyword}
|
||||
if opts.Actor == nil {
|
||||
emailCond = emailCond.And(builder.Eq{"keep_email_private": false})
|
||||
} else if !opts.Actor.IsAdmin {
|
||||
emailCond = emailCond.And(
|
||||
builder.Or(
|
||||
builder.Eq{"keep_email_private": false},
|
||||
builder.Eq{"id": opts.Actor.ID},
|
||||
),
|
||||
)
|
||||
}
|
||||
keywordCond = keywordCond.Or(emailCond)
|
||||
}
|
||||
|
||||
cond = cond.And(keywordCond)
|
||||
|
|
|
@ -217,7 +217,7 @@ type EditRepoOption struct {
|
|||
Archived *bool `json:"archived,omitempty"`
|
||||
// set to a string like `8h30m0s` to set the mirror interval time
|
||||
MirrorInterval *string `json:"mirror_interval,omitempty"`
|
||||
// enable prune - remove obsolete remote-tracking references
|
||||
// enable prune - remove obsolete remote-tracking references when mirroring
|
||||
EnablePrune *bool `json:"enable_prune,omitempty"`
|
||||
}
|
||||
|
||||
|
|
|
@ -1062,16 +1062,10 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
|
|||
func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
// only update mirror if interval or enable prune are provided
|
||||
if opts.MirrorInterval == nil && opts.EnablePrune == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// these values only make sense if the repo is a mirror
|
||||
// Skip this update if the repo is not a mirror, do not return error.
|
||||
// Because reporting errors only makes the logic more complex&fragile, it doesn't really help end users.
|
||||
if !repo.IsMirror {
|
||||
err := fmt.Errorf("repo is not a mirror, can not change mirror interval")
|
||||
ctx.Error(http.StatusUnprocessableEntity, err.Error(), err)
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// get the mirror from the repo
|
||||
|
|
|
@ -68,11 +68,12 @@ func Search(ctx *context.APIContext) {
|
|||
users = []*user_model.User{user_model.NewActionsUser()}
|
||||
default:
|
||||
users, maxResults, err = user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
|
||||
Actor: ctx.Doer,
|
||||
Keyword: ctx.FormTrim("q"),
|
||||
UID: uid,
|
||||
Type: user_model.UserTypeIndividual,
|
||||
ListOptions: listOptions,
|
||||
Actor: ctx.Doer,
|
||||
Keyword: ctx.FormTrim("q"),
|
||||
UID: uid,
|
||||
Type: user_model.UserTypeIndividual,
|
||||
SearchByEmail: true,
|
||||
ListOptions: listOptions,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, map[string]any{
|
||||
|
|
2
templates/swagger/v1_json.tmpl
generated
2
templates/swagger/v1_json.tmpl
generated
|
@ -20753,7 +20753,7 @@
|
|||
"x-go-name": "Description"
|
||||
},
|
||||
"enable_prune": {
|
||||
"description": "enable prune - remove obsolete remote-tracking references",
|
||||
"description": "enable prune - remove obsolete remote-tracking references when mirroring",
|
||||
"type": "boolean",
|
||||
"x-go-name": "EnablePrune"
|
||||
},
|
||||
|
|
|
@ -109,3 +109,39 @@ func TestAPIUserSearchNotLoggedInUserHidden(t *testing.T) {
|
|||
DecodeJSON(t, resp, &results)
|
||||
assert.Empty(t, results.Data)
|
||||
}
|
||||
|
||||
func TestAPIUserSearchByEmail(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
// admin can search user with private email
|
||||
adminUsername := "user1"
|
||||
session := loginUser(t, adminUsername)
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadUser)
|
||||
query := "user2@example.com"
|
||||
req := NewRequestf(t, "GET", "/api/v1/users/search?q=%s", query).
|
||||
AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var results SearchResults
|
||||
DecodeJSON(t, resp, &results)
|
||||
assert.Equal(t, 1, len(results.Data))
|
||||
assert.Equal(t, query, results.Data[0].Email)
|
||||
|
||||
// no login user can not search user with private email
|
||||
req = NewRequestf(t, "GET", "/api/v1/users/search?q=%s", query)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &results)
|
||||
assert.Empty(t, results.Data)
|
||||
|
||||
// user can search self with private email
|
||||
user2 := "user2"
|
||||
session = loginUser(t, user2)
|
||||
token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadUser)
|
||||
req = NewRequestf(t, "GET", "/api/v1/users/search?q=%s", query).
|
||||
AddTokenAuth(token)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
DecodeJSON(t, resp, &results)
|
||||
assert.Equal(t, 1, len(results.Data))
|
||||
assert.Equal(t, query, results.Data[0].Email)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user