Skip to content
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

Open
wants to merge 31 commits into
base: multiple-owner-support
Choose a base branch
from

Conversation

aryan-bhokare
Copy link
Contributor

@aryan-bhokare aryan-bhokare commented Apr 24, 2024

Proposed changes

  1. Added new Route '/projects'.
  2. Added ProjectDashboard.

Types of changes

What types of changes does your code introduce to Litmus? Put an x in the boxes that apply

  • New feature (non-breaking change which adds functionality)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices applies)

Checklist

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.

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Dependency

Pr #4536

Special notes for your reviewer:

Test Scenarios

  • Project can have multiple project owners so checking RBACs by switching users(owners).
  • Can invite with the owner role.
  • User cannot change his own role to avoid last owner changing his role.
  • User cannot remove invitation of themselves to avoid the last owner to leave.
  • Last project owner leaves.
  • Owner can remove other owners.

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>
@aryan-bhokare
Copy link
Contributor Author

@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>
@aryan-bhokare aryan-bhokare marked this pull request as ready for review May 10, 2024 12:25
@Saranya-jena Saranya-jena changed the title [WIP] Multiple project owner frontend. Feat: Added support for multiple project owners May 22, 2024
@@ -333,10 +349,12 @@ func CreateProject(service services.ApplicationService) gin.HandlerFunc {
members = append(members, newMember)
state := "active"
Copy link
Contributor

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 (
Copy link
Contributor

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

Copy link
Contributor Author

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/authentication/pkg/project/repository.go Outdated Show resolved Hide resolved
Copy link
Member

@SahilKr24 SahilKr24 left a 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.

Copy link
Member

@hrishavjha hrishavjha left a 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 🚀

aryan-bhokare and others added 4 commits May 25, 2024 15:19
…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
Copy link
Contributor

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

Comment on lines +92 to +94
pipelineCount = append(pipeline, bson.D{
{"$count", "totalNumberOfProjects"},
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pipelineCount = append(pipeline, bson.D{
{"$count", "totalNumberOfProjects"},
})
pipeline = append(pipeline, bson.D{
{"$count", "totalNumberOfProjects"},
})

Copy link
Contributor

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.

Comment on lines +186 to +203
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
}

Copy link
Contributor

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))
}

Copy link
Contributor

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

Comment on lines +79 to +80
Projects []*Project `json:"projects"`
TotalNumberOfProjects *int64 `json:"totalNumberOfProjects"`
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants