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
Feat: Added support for multiple project owners #4597
base: multiple-owner-support
Are you sure you want to change the base?
Changes from all commits
3a4ee69
d2d8f17
e9d81ad
e0b4518
43bdca2
d368644
409beb9
28b890c
3255daa
f528e10
b0cc1ce
415a34f
1fa5917
8d5113e
1eeae8b
be4086a
c991380
d8c14df
7b9f489
8b5bf97
724c606
d60cf2e
2eb6a17
a3d5b60
923d281
a24ba5e
6747199
554e008
42da32e
4dbd103
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 |
---|---|---|
|
@@ -55,14 +55,17 @@ func GetUserWithProject(service services.ApplicationService) gin.HandlerFunc { | |
|
||
outputUser := user.GetUserWithProject() | ||
|
||
projects, err := service.GetProjectsByUserID(outputUser.ID, false) | ||
request := utils.GetProjectFilters(c) | ||
request.UserID = outputUser.ID | ||
|
||
response, err := service.GetProjectsByUserID(request) | ||
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. Can we remove the user.GetUserWithProject() func call completely and use just the above function? Either we can get userID from getUser() or tweak the above function to search by username as well 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 we remove user.GetUserWithProject and user GetUser and GetProjectsByUserID |
||
if err != nil { | ||
log.Error(err) | ||
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) | ||
return | ||
} | ||
|
||
outputUser.Projects = projects | ||
outputUser.Projects = response.Projects | ||
|
||
c.JSON(http.StatusOK, gin.H{"data": outputUser}) | ||
} | ||
|
@@ -119,9 +122,10 @@ func GetProject(service services.ApplicationService) gin.HandlerFunc { | |
// GetProjectsByUserID queries the project with a given userID from the database and returns it in the appropriate format | ||
func GetProjectsByUserID(service services.ApplicationService) gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
uID := c.MustGet("uid").(string) | ||
projects, err := service.GetProjectsByUserID(uID, false) | ||
if projects == nil { | ||
request := utils.GetProjectFilters(c) | ||
|
||
response, err := service.GetProjectsByUserID(request) | ||
if response == nil || (response.TotalNumberOfProjects != nil && *response.TotalNumberOfProjects == 0) { | ||
c.JSON(http.StatusOK, gin.H{ | ||
"message": "No projects found", | ||
}) | ||
|
@@ -132,7 +136,7 @@ func GetProjectsByUserID(service services.ApplicationService) gin.HandlerFunc { | |
return | ||
} | ||
|
||
c.JSON(http.StatusOK, gin.H{"data": projects}) | ||
c.JSON(http.StatusOK, gin.H{"data": response}) | ||
} | ||
} | ||
|
||
|
@@ -300,6 +304,18 @@ func CreateProject(service services.ApplicationService) gin.HandlerFunc { | |
return | ||
} | ||
|
||
if userRequest.Description == nil { | ||
// If description is not provided, set it to an empty string | ||
emptyDescription := "" | ||
userRequest.Description = &emptyDescription | ||
} | ||
|
||
if userRequest.Tags == nil { | ||
// If tags are not provided, set it to an empty slice | ||
emptyTags := make([]*string, 0) | ||
userRequest.Tags = emptyTags | ||
} | ||
|
||
userRequest.UserID = c.MustGet("uid").(string) | ||
|
||
user, err := service.GetUser(userRequest.UserID) | ||
|
@@ -333,10 +349,12 @@ func CreateProject(service services.ApplicationService) gin.HandlerFunc { | |
members = append(members, newMember) | ||
state := "active" | ||
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. create an enum for the states |
||
newProject := &entities.Project{ | ||
ID: pID, | ||
Name: userRequest.ProjectName, | ||
Members: members, | ||
State: &state, | ||
ID: pID, | ||
Name: userRequest.ProjectName, | ||
Members: members, | ||
State: &state, | ||
Description: userRequest.Description, | ||
Tags: userRequest.Tags, | ||
Audit: entities.Audit{ | ||
IsRemoved: false, | ||
CreatedAt: time.Now().UnixMilli(), | ||
|
@@ -591,7 +609,7 @@ func LeaveProject(service services.ApplicationService) gin.HandlerFunc { | |
c.JSON(utils.ErrorStatusCodes[utils.ErrInvalidRequest], presenter.CreateErrorResponse(utils.ErrInvalidRequest)) | ||
return | ||
} | ||
|
||
if member.Role != nil && *member.Role == entities.RoleOwner { | ||
owners, err := service.GetProjectOwners(member.ProjectID) | ||
if err != nil { | ||
|
@@ -605,7 +623,7 @@ func LeaveProject(service services.ApplicationService) gin.HandlerFunc { | |
return | ||
} | ||
} | ||
|
||
err = validations.RbacValidator(c.MustGet("uid").(string), member.ProjectID, | ||
validations.MutationRbacRules["leaveProject"], | ||
string(entities.AcceptedInvitation), | ||
|
@@ -787,7 +805,7 @@ func UpdateMemberRole(service services.ApplicationService) gin.HandlerFunc { | |
return | ||
} | ||
|
||
|
||
// Validating member role | ||
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)) | ||
|
@@ -805,13 +823,13 @@ func UpdateMemberRole(service services.ApplicationService) gin.HandlerFunc { | |
presenter.CreateErrorResponse(utils.ErrUnauthorized)) | ||
return | ||
} | ||
|
||
uid := c.MustGet("uid").(string) | ||
if uid == member.UserID { | ||
c.JSON(http.StatusBadRequest, gin.H{"message": "User cannot change their own role."}) | ||
return | ||
} | ||
|
||
err = service.UpdateMemberRole(member.ProjectID, member.UserID, member.Role) | ||
if err != nil { | ||
log.Error(err) | ||
|
@@ -895,7 +913,7 @@ func GetProjectRole(service services.ApplicationService) gin.HandlerFunc { | |
|
||
} | ||
} | ||
|
||
// DeleteProject godoc | ||
// | ||
// @Description Delete a project. | ||
|
@@ -930,7 +948,7 @@ func DeleteProject (service services.ApplicationService) gin.HandlerFunc { | |
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, gin.H{ | ||
"message": "Successfully deleted project.", | ||
}) | ||
|
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.
Does the function return any error which needs to be handled?
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.
umm it actually does not return any error