Fix #761
This commit is contained in:
Daniel Jiang 2016-09-20 12:46:17 +08:00 committed by GitHub
commit 42d0f968d3
2 changed files with 17 additions and 8 deletions

View File

@ -142,13 +142,22 @@ func (pma *ProjectMemberAPI) Post() {
return
}
for _, rid := range req.Roles {
err = dao.AddProjectMember(projectID, userID, int(rid))
if err != nil {
log.Errorf("Failed to update DB to add project user role, project id: %d, user id: %d, role id: %d", projectID, userID, rid)
pma.RenderError(http.StatusInternalServerError, "Failed to update data in database")
return
}
if len(req.Roles) <= 0 || len(req.Roles) > 1 {
pma.CustomAbort(http.StatusBadRequest, "only one role is supported")
}
rid := req.Roles[0]
if !(rid == models.PROJECTADMIN ||
rid == models.DEVELOPER ||
rid == models.GUEST) {
pma.CustomAbort(http.StatusBadRequest, "invalid role")
}
err = dao.AddProjectMember(projectID, userID, rid)
if err != nil {
log.Errorf("Failed to update DB to add project user role, project id: %d, user id: %d, role id: %d", projectID, userID, rid)
pma.RenderError(http.StatusInternalServerError, "Failed to update data in database")
return
}
}

View File

@ -314,7 +314,7 @@ paths:
description: Relevant project ID.
- name: roles
in: body
description: Role members for adding to relevant project.
description: Role members for adding to relevant project. Only one role is supported in the role list.
schema:
$ref: '#/definitions/RoleParam'
tags: