Skip to content

Commit 87c9692

Browse files
Merge branch 'master' into improve-strings
2 parents 3e0a69f + 1bb5c09 commit 87c9692

File tree

8 files changed

+76
-25
lines changed

8 files changed

+76
-25
lines changed

integrations/api_admin_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package integrations
66

77
import (
8+
"encoding/json"
89
"fmt"
910
"net/http"
1011
"testing"
@@ -163,3 +164,32 @@ func TestAPICreateUserInvalidEmail(t *testing.T) {
163164
})
164165
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
165166
}
167+
168+
func TestAPIEditUser(t *testing.T) {
169+
defer prepareTestEnv(t)()
170+
adminUsername := "user1"
171+
session := loginUser(t, adminUsername)
172+
token := getTokenForLoggedInUser(t, session)
173+
urlStr := fmt.Sprintf("/api/v1/admin/users/%s?token=%s", "user2", token)
174+
175+
req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{
176+
// required
177+
"login_name": "user2",
178+
"source_id": "0",
179+
// to change
180+
"full_name": "Full Name User 2",
181+
})
182+
session.MakeRequest(t, req, http.StatusOK)
183+
184+
empty := ""
185+
req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
186+
LoginName: "user2",
187+
SourceID: 0,
188+
Email: &empty,
189+
})
190+
resp := session.MakeRequest(t, req, http.StatusUnprocessableEntity)
191+
192+
errMap := make(map[string]interface{})
193+
json.Unmarshal(resp.Body.Bytes(), &errMap)
194+
assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string))
195+
}

modules/migrations/gitlab.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, username, passw
9292
pathParts := strings.Split(strings.Trim(repoPath, "/"), "/")
9393
var resp *gitlab.Response
9494
u, _ := url.Parse(baseURL)
95-
for len(pathParts) > 2 {
95+
for len(pathParts) >= 2 {
9696
_, resp, err = gitlabClient.Version.GetVersion()
9797
if err == nil || resp != nil && resp.StatusCode == 401 {
9898
err = nil // if no authentication given, this still should work
@@ -609,8 +609,12 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
609609

610610
// GetReviews returns pull requests review
611611
func (g *GitlabDownloader) GetReviews(pullRequestNumber int64) ([]*base.Review, error) {
612-
state, _, err := g.client.MergeRequestApprovals.GetApprovalState(g.repoID, int(pullRequestNumber), gitlab.WithContext(g.ctx))
612+
state, resp, err := g.client.MergeRequestApprovals.GetApprovalState(g.repoID, int(pullRequestNumber), gitlab.WithContext(g.ctx))
613613
if err != nil {
614+
if resp != nil && resp.StatusCode == 404 {
615+
log.Error(fmt.Sprintf("GitlabDownloader: while migrating a error occurred: '%s'", err.Error()))
616+
return []*base.Review{}, nil
617+
}
614618
return nil, err
615619
}
616620

modules/structs/admin_user.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@ type CreateUserOption struct {
2323

2424
// EditUserOption edit user options
2525
type EditUserOption struct {
26-
SourceID int64 `json:"source_id"`
27-
LoginName string `json:"login_name"`
28-
FullName string `json:"full_name" binding:"MaxSize(100)"`
2926
// required: true
27+
SourceID int64 `json:"source_id"`
28+
// required: true
29+
LoginName string `json:"login_name" binding:"Required"`
3030
// swagger:strfmt email
31-
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
32-
Password string `json:"password" binding:"MaxSize(255)"`
33-
MustChangePassword *bool `json:"must_change_password"`
34-
Website string `json:"website" binding:"MaxSize(50)"`
35-
Location string `json:"location" binding:"MaxSize(50)"`
36-
Active *bool `json:"active"`
37-
Admin *bool `json:"admin"`
38-
AllowGitHook *bool `json:"allow_git_hook"`
39-
AllowImportLocal *bool `json:"allow_import_local"`
40-
MaxRepoCreation *int `json:"max_repo_creation"`
41-
ProhibitLogin *bool `json:"prohibit_login"`
42-
AllowCreateOrganization *bool `json:"allow_create_organization"`
31+
Email *string `json:"email" binding:"MaxSize(254)"`
32+
FullName *string `json:"full_name" binding:"MaxSize(100)"`
33+
Password string `json:"password" binding:"MaxSize(255)"`
34+
MustChangePassword *bool `json:"must_change_password"`
35+
Website *string `json:"website" binding:"MaxSize(50)"`
36+
Location *string `json:"location" binding:"MaxSize(50)"`
37+
Active *bool `json:"active"`
38+
Admin *bool `json:"admin"`
39+
AllowGitHook *bool `json:"allow_git_hook"`
40+
AllowImportLocal *bool `json:"allow_import_local"`
41+
MaxRepoCreation *int `json:"max_repo_creation"`
42+
ProhibitLogin *bool `json:"prohibit_login"`
43+
AllowCreateOrganization *bool `json:"allow_create_organization"`
4344
}

routers/api/v1/admin/user.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
155155
return
156156
}
157157

158-
if len(form.Password) > 0 {
158+
if len(form.Password) != 0 {
159159
if !password.IsComplexEnough(form.Password) {
160160
err := errors.New("PasswordComplexity")
161161
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
@@ -182,10 +182,23 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
182182
}
183183

184184
u.LoginName = form.LoginName
185-
u.FullName = form.FullName
186-
u.Email = form.Email
187-
u.Website = form.Website
188-
u.Location = form.Location
185+
186+
if form.FullName != nil {
187+
u.FullName = *form.FullName
188+
}
189+
if form.Email != nil {
190+
u.Email = *form.Email
191+
if len(u.Email) == 0 {
192+
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("email is not allowed to be empty string"))
193+
return
194+
}
195+
}
196+
if form.Website != nil {
197+
u.Website = *form.Website
198+
}
199+
if form.Location != nil {
200+
u.Location = *form.Location
201+
}
189202
if form.Active != nil {
190203
u.IsActive = *form.Active
191204
}

routers/repo/issue.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
131131
posterID = ctx.User.ID
132132
case "mentioned":
133133
mentionedID = ctx.User.ID
134+
case "assigned":
135+
assigneeID = ctx.User.ID
134136
}
135137
}
136138

templates/repo/issue/list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
</span>
9494
<div class="menu">
9595
<a class="{{if eq .ViewType "all"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=all&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.all_issues"}}</a>
96-
<a class="{{if eq .ViewType "assigned"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=assigned&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{.SignedUser.ID}}">{{.i18n.Tr "repo.issues.filter_type.assigned_to_you"}}</a>
96+
<a class="{{if eq .ViewType "assigned"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=assigned&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.assigned_to_you"}}</a>
9797
<a class="{{if eq .ViewType "created_by"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=created_by&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.created_by_you"}}</a>
9898
<a class="{{if eq .ViewType "mentioned"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=mentioned&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.mentioning_you"}}</a>
9999
</div>

templates/repo/issue/milestone_issues.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
</span>
9292
<div class="menu">
9393
<a class="{{if eq .ViewType "all"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=all&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.all_issues"}}</a>
94-
<a class="{{if eq .ViewType "assigned"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=assigned&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&assignee={{.SignedUser.ID}}">{{.i18n.Tr "repo.issues.filter_type.assigned_to_you"}}</a>
94+
<a class="{{if eq .ViewType "assigned"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=assigned&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.assigned_to_you"}}</a>
9595
<a class="{{if eq .ViewType "created_by"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=created_by&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.created_by_you"}}</a>
9696
<a class="{{if eq .ViewType "mentioned"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=mentioned&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.mentioning_you"}}</a>
9797
</div>

templates/swagger/v1_json.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13097,7 +13097,8 @@
1309713097
"description": "EditUserOption edit user options",
1309813098
"type": "object",
1309913099
"required": [
13100-
"email"
13100+
"source_id",
13101+
"login_name"
1310113102
],
1310213103
"properties": {
1310313104
"active": {

0 commit comments

Comments
 (0)