-
Notifications
You must be signed in to change notification settings - Fork 694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] : Multiple project owner backend. #4536
Changes from 10 commits
78b82ab
962175b
0c8528e
aeb1085
64867b8
eacb880
1de73da
7c79813
44ae3b9
77bcd91
43bd3b2
2ac9f7d
1860721
a2a27d4
4e8279a
737c03f
c1b2ed3
197aabd
4a10fe3
33dec51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,6 +195,30 @@ func GetActiveProjectMembers(service services.ApplicationService) gin.HandlerFun | |
} | ||
} | ||
|
||
// GetActiveProjectOwners godoc | ||
// | ||
// @Summary Get active project Owners. | ||
// @Description Return list of active project owners. | ||
// @Tags ProjectRouter | ||
// @Param state path string true "State" | ||
// @Accept json | ||
// @Produce json | ||
// @Failure 500 {object} response.ErrServerError | ||
// @Success 200 {object} response.Response{} | ||
// @Router /get_project_owners/:project_id/:state [get] | ||
func GetActiveProjectOwners(service services.ApplicationService) gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
projectID := c.Param("project_id") | ||
// state := c.Param("state") | ||
owners, err := service.GetProjectOwners(projectID) | ||
if err != nil { | ||
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) | ||
return | ||
} | ||
c.JSON(http.StatusOK, gin.H{"data": owners}) | ||
} | ||
} | ||
|
||
// getInvitation returns the Invitation status | ||
func getInvitation(service services.ApplicationService, member entities.MemberInput) (entities.Invitation, error) { | ||
project, err := service.GetProjectByProjectID(member.ProjectID) | ||
|
@@ -380,7 +404,7 @@ func SendInvitation(service services.ApplicationService) gin.HandlerFunc { | |
return | ||
} | ||
// Validating member role | ||
if member.Role == nil || (*member.Role != entities.RoleEditor && *member.Role != entities.RoleViewer) { | ||
if member.Role == nil || (*member.Role != entities.RoleEditor && *member.Role != entities.RoleViewer && *member.Role != entities.RoleOwner) { | ||
c.JSON(utils.ErrorStatusCodes[utils.ErrInvalidRole], presenter.CreateErrorResponse(utils.ErrInvalidRole)) | ||
return | ||
} | ||
|
@@ -569,6 +593,20 @@ func LeaveProject(service services.ApplicationService) gin.HandlerFunc { | |
return | ||
} | ||
|
||
if member.Role == entities.RoleOwner { | ||
owners, err := service.GetProjectsOwners(member.ProjectID) | ||
if err != nil { | ||
log.Error(err) | ||
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) | ||
return | ||
} | ||
|
||
if len(owners) == 1 { | ||
c.JSON(utils.ErrorStatusCodes[utils.ErrInvalidRequest], gin.H{"message": "Cannot leave project. There must be at least one owner."}) | ||
return | ||
} | ||
} | ||
|
||
err = validations.RbacValidator(c.MustGet("uid").(string), member.ProjectID, | ||
validations.MutationRbacRules["leaveProject"], | ||
string(entities.AcceptedInvitation), | ||
|
@@ -726,6 +764,55 @@ func UpdateProjectName(service services.ApplicationService) gin.HandlerFunc { | |
} | ||
} | ||
|
||
// UpdateMemberRole godoc | ||
// | ||
// @Summary Update member role. | ||
// @Description Return updated member role. | ||
// @Tags ProjectRouter | ||
// @Accept json | ||
// @Produce json | ||
// @Failure 400 {object} response.ErrInvalidRequest | ||
// @Failure 401 {object} response.ErrUnauthorized | ||
// @Failure 500 {object} response.ErrServerError | ||
// @Success 200 {object} response.Response{} | ||
// @Router /update_member_role [post] | ||
// | ||
// UpdateMemberRole is used to update a member role in the project | ||
func UpdateMemberRole(service services.ApplicationService) gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
var member entities.MemberInput | ||
err := c.BindJSON(&member) | ||
if err != nil { | ||
log.Warn(err) | ||
c.JSON(utils.ErrorStatusCodes[utils.ErrInvalidRequest], presenter.CreateErrorResponse(utils.ErrInvalidRequest)) | ||
return | ||
} | ||
|
||
err = validations.RbacValidator(c.MustGet("uid").(string), | ||
member.ProjectID, | ||
validations.MutationRbacRules["updateMemberRole"], | ||
string(entities.AcceptedInvitation), | ||
service) | ||
if err != nil { | ||
log.Warn(err) | ||
c.JSON(utils.ErrorStatusCodes[utils.ErrUnauthorized], | ||
presenter.CreateErrorResponse(utils.ErrUnauthorized)) | ||
return | ||
} | ||
|
||
err = service.UpdateMemberRole(member.ProjectID, member.UserID, member.Role) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also add one more check for a case: There is only 1 owner and that owner is trying update their role to viewer/editor. In this case there will be no project owner. 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure I'll do that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about a check to not allow the logged in user to change their own project roles. This will cover all the conditions. Please check on feasibility of this approach and race conditions if any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that would be better. cc: @aryan-bhokare |
||
log.Error(err) | ||
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, gin.H{ | ||
"message": "Successfully updated Role", | ||
}) | ||
} | ||
} | ||
|
||
// GetOwnerProjects godoc | ||
// | ||
// @Summary Get projects owner. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4325,9 +4325,9 @@ flatted@^3.2.9: | |
integrity sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw== | ||
|
||
follow-redirects@^1.0.0, follow-redirects@^1.15.0: | ||
version "1.15.5" | ||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.5.tgz#54d4d6d062c0fa7d9d17feb008461550e3ba8020" | ||
integrity sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw== | ||
version "1.15.6" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this change required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It happened automatically. I am unable to understand I was thinking about starting new from the commit before the bumps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these changes were included in the main litmus repo I will remove it from the pr. |
||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" | ||
integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== | ||
|
||
fork-ts-checker-webpack-plugin@^6.3.4: | ||
version "6.5.0" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove if not required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure