mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 04:35:16 +01:00
Merge pull request #4808 from stonezdj/master
Merge pull request #4798 from stonezdj/release-1.5.0
This commit is contained in:
commit
413ae9a8cb
@ -513,7 +513,7 @@ paths:
|
|||||||
'403':
|
'403':
|
||||||
description: User in session does not have permission to the project.
|
description: User in session does not have permission to the project.
|
||||||
'404':
|
'404':
|
||||||
description: Project does not exist.
|
description: Project does not exist, or the username does not found, or the user group does not found.
|
||||||
'500':
|
'500':
|
||||||
description: Unexpected internal errors.
|
description: Unexpected internal errors.
|
||||||
'/projects/{project_id}/members/{mid}':
|
'/projects/{project_id}/members/{mid}':
|
||||||
|
@ -122,6 +122,10 @@ func (pma *ProjectMemberAPI) Post() {
|
|||||||
var request models.MemberReq
|
var request models.MemberReq
|
||||||
pma.DecodeJSONReq(&request)
|
pma.DecodeJSONReq(&request)
|
||||||
pmid, err := AddOrUpdateProjectMember(projectID, request)
|
pmid, err := AddOrUpdateProjectMember(projectID, request)
|
||||||
|
if err == auth.ErrorGroupNotExist || err == auth.ErrorUserNotExist {
|
||||||
|
pma.HandleNotFound(fmt.Sprintf("Failed to add project member, error: %v", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pma.HandleInternalServerError(fmt.Sprintf("Failed to add project member, error: %v", err))
|
pma.HandleInternalServerError(fmt.Sprintf("Failed to add project member, error: %v", err))
|
||||||
return
|
return
|
||||||
|
@ -114,6 +114,20 @@ func TestProjectMemberAPI_Post(t *testing.T) {
|
|||||||
},
|
},
|
||||||
code: http.StatusCreated,
|
code: http.StatusCreated,
|
||||||
},
|
},
|
||||||
|
&codeCheckingCase{
|
||||||
|
request: &testingRequest{
|
||||||
|
method: http.MethodPost,
|
||||||
|
url: "/api/projects/1/members",
|
||||||
|
bodyJSON: &models.MemberReq{
|
||||||
|
Role: 1,
|
||||||
|
MemberUser: models.User{
|
||||||
|
Username: "notexistuser",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
credential: admin,
|
||||||
|
},
|
||||||
|
code: http.StatusNotFound,
|
||||||
|
},
|
||||||
&codeCheckingCase{
|
&codeCheckingCase{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
|
@ -31,6 +31,12 @@ const frozenTime time.Duration = 1500 * time.Millisecond
|
|||||||
|
|
||||||
var lock = NewUserLock(frozenTime)
|
var lock = NewUserLock(frozenTime)
|
||||||
|
|
||||||
|
// ErrorUserNotExist ...
|
||||||
|
var ErrorUserNotExist = errors.New("User does not exist")
|
||||||
|
|
||||||
|
// ErrorGroupNotExist ...
|
||||||
|
var ErrorGroupNotExist = errors.New("Group does not exist")
|
||||||
|
|
||||||
//ErrAuth is the type of error to indicate a failed authentication due to user's error.
|
//ErrAuth is the type of error to indicate a failed authentication due to user's error.
|
||||||
type ErrAuth struct {
|
type ErrAuth struct {
|
||||||
details string
|
details string
|
||||||
@ -200,6 +206,9 @@ func SearchGroup(groupKey string) (*models.UserGroup, error) {
|
|||||||
// SearchAndOnBoardUser ... Search user and OnBoard user, if user exist, return the ID of current user.
|
// SearchAndOnBoardUser ... Search user and OnBoard user, if user exist, return the ID of current user.
|
||||||
func SearchAndOnBoardUser(username string) (int, error) {
|
func SearchAndOnBoardUser(username string) (int, error) {
|
||||||
user, err := SearchUser(username)
|
user, err := SearchUser(username)
|
||||||
|
if user == nil {
|
||||||
|
return 0, ErrorUserNotExist
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@ -215,6 +224,9 @@ func SearchAndOnBoardUser(username string) (int, error) {
|
|||||||
// SearchAndOnBoardGroup ... if altGroupName is not empty, take the altGroupName as groupName in harbor DB
|
// SearchAndOnBoardGroup ... if altGroupName is not empty, take the altGroupName as groupName in harbor DB
|
||||||
func SearchAndOnBoardGroup(groupKey, altGroupName string) (int, error) {
|
func SearchAndOnBoardGroup(groupKey, altGroupName string) (int, error) {
|
||||||
userGroup, err := SearchGroup(groupKey)
|
userGroup, err := SearchGroup(groupKey)
|
||||||
|
if userGroup == nil {
|
||||||
|
return 0, ErrorGroupNotExist
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user