-
Notifications
You must be signed in to change notification settings - Fork 654
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?
Feat: Added support for multiple project owners #4597
Conversation
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Added a modal CreateProject with it's controller and views. Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
@hrishavjha @SahilKr24 @Saranya-jena PTAL :) |
Added new fields in `Project` struct. Added fields for filters, pagination, and some constants. Modified `CreateProjectInput`. Signed-off-by: aryan <aryan1bhokare@gmail.com>
Added Filters and pagination in Backend. Modified API's and added a pipeline for the aggregation of results. Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
chaoscenter/authentication/api/handlers/rest/project_handler.go
Outdated
Show resolved
Hide resolved
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
create an enum for the states
Ascending *bool `json:"ascending"` | ||
} | ||
|
||
const ( |
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.
if this is being used by the APIs, do not keep it here. create a common file where other resources(user) can also used these fields
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 u suggest where should I keep them
chaoscenter/web/src/components/ProjectDashboardCardContainer/ProjectDashboardCardContainer.tsx
Outdated
Show resolved
Hide resolved
chaoscenter/web/src/components/ProjectDashboardCardContainer/ProjectDashboardCardContainer.tsx
Outdated
Show resolved
Hide resolved
chaoscenter/web/src/controllers/ProjectDashboardCardMenu/ProjectDashboardCardMenu.tsx
Outdated
Show resolved
Hide resolved
chaoscenter/web/src/controllers/ProjectDashboard/ProjectFilters.tsx
Outdated
Show resolved
Hide resolved
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.
Nothing that seems worthy of a change request. General feedback and some optimisations.
Code is clean, precise and less than 128 lines per file. Looks good to me. Great job.
chaoscenter/web/src/components/ProjectDashboardCardContainer/ProjectDashboardCardContainer.tsx
Outdated
Show resolved
Hide resolved
chaoscenter/web/src/components/ProjectDashboardCardContainer/ProjectDashboardCardContainer.tsx
Outdated
Show resolved
Hide resolved
chaoscenter/web/src/components/ProjectDashboardCardContainer/ProjectDashboardCardContainer.tsx
Outdated
Show resolved
Hide resolved
chaoscenter/web/src/views/ProjectDashboard/ProjectDashboard.tsx
Outdated
Show resolved
Hide resolved
chaoscenter/web/src/views/ProjectDashboard/ProjectDashboard.tsx
Outdated
Show resolved
Hide resolved
chaoscenter/web/src/views/ProjectDashboard/ProjectDashboard.tsx
Outdated
Show resolved
Hide resolved
chaoscenter/web/src/views/ProjectDashboardCardMenu/ProjectDashboardCardMenu.tsx
Outdated
Show resolved
Hide resolved
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.
A Few minor improvements can be made as mentioned in the comments, rest of the changes LGTM 🚀
…s.tsx Co-authored-by: Hrishav <hrishav.kumar@harness.io> Signed-off-by: Aryan Bhokare <92683836+aryan-bhokare@users.noreply.github.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
Signed-off-by: aryan <aryan1bhokare@gmail.com>
} | ||
|
||
result, err := r.Collection.Find(context.TODO(), query) | ||
// count stage | ||
var pipelineCount mongo.Pipeline |
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.
You can directly append the count query in pipeline instead of creating another mongo pipeline
pipelineCount = append(pipeline, bson.D{ | ||
{"$count", "totalNumberOfProjects"}, | ||
}) |
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.
pipelineCount = append(pipeline, bson.D{ | |
{"$count", "totalNumberOfProjects"}, | |
}) | |
pipeline = append(pipeline, bson.D{ | |
{"$count", "totalNumberOfProjects"}, | |
}) |
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.
For this pipeline, you can take ref from: https://github.com/litmuschaos/litmus/blob/master/chaoscenter/graphql/server/pkg/chaos_experiment/handler/handler.go#L508
You can utilise facet stage, which performs multiple operations in parallel. This will help us reduce 1 DB call per request.
func CreatePaginationStage(pagination *entities.Pagination) []bson.D { | ||
var stages []bson.D | ||
if pagination != nil { | ||
page := pagination.Page | ||
limit := pagination.Limit | ||
stages = append(stages, bson.D{ | ||
{"$skip", page * limit}, | ||
}) | ||
stages = append(stages, bson.D{ | ||
{"$limit", limit}, | ||
}) | ||
} else { | ||
stages = append(stages, bson.D{ | ||
{"$limit", 10}, | ||
}) | ||
} | ||
return stages | ||
} |
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.
func CreatePaginationStage(pagination *entities.Pagination) []bson.D { | |
var stages []bson.D | |
if pagination != nil { | |
page := pagination.Page | |
limit := pagination.Limit | |
stages = append(stages, bson.D{ | |
{"$skip", page * limit}, | |
}) | |
stages = append(stages, bson.D{ | |
{"$limit", limit}, | |
}) | |
} else { | |
stages = append(stages, bson.D{ | |
{"$limit", 10}, | |
}) | |
} | |
return stages | |
} | |
func CreatePaginationStage(pagination *entities.Pagination) bson.D { | |
var stages bson.D | |
if pagination != nil { | |
page := pagination.Page | |
limit := pagination.Limit | |
if pagination.Limit > 50 { | |
limit = 50 | |
} | |
stages = append(stages, bson.E{ | |
{"$skip", page * limit}, | |
}) | |
stages = append(stages, bson.E{ | |
{"$limit", limit}, | |
}) | |
} else { | |
stages = append(stages, bson.E{ | |
{"$limit", 10}, | |
}) | |
} | |
return stages | |
} |
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.
An upper limit of 50 can be set to prevent exceeding the max limit (16 MB) allowed to be shared over the network.
if len(countResult) > 0 { | ||
totalNumberOfProjects = int64(countResult[0]["totalNumberOfProjects"].(int32)) | ||
} | ||
|
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.
A check can be added to return in case the number of projects = 0
Projects []*Project `json:"projects"` | ||
TotalNumberOfProjects *int64 `json:"totalNumberOfProjects"` |
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.
Both the fields can be made mandatory, since these fields will always be returned in the response. Empty array can be returned in projects in case no projects are found
// Iterate over the cursor and decode the results into projects | ||
for cursor.Next(context.TODO()) { | ||
var project entities.Project | ||
if err := cursor.Decode(&project); err != nil { |
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.
Instead of looping over cursor, cursor.All can be used to decode multiple elements in the map
|
||
// Extract count result | ||
var countResult []bson.M | ||
if err := countCursor.All(context.TODO(), &countResult); err != nil { |
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.
Please define a context at the top, and use that variable everywhere else, using separate instance of context everywhere does not makes sense.
"go.mongodb.org/mongo-driver/bson/primitive" | ||
) | ||
|
||
func GetProjectFilters(c *gin.Context) *entities.ListProjectRequest { |
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.
Functions in this package can be updated by taking ref from: https://github.com/litmuschaos/litmus/blob/master/chaoscenter/graphql/server/pkg/chaos_experiment/handler/handler.go#L508
Proposed changes
ProjectDashboard
.Types of changes
What types of changes does your code introduce to Litmus? Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Dependency
Pr #4536
Special notes for your reviewer:
Test Scenarios