absmach / magistrala

Industrial IoT Messaging and Device Management Platform
https://www.abstractmachines.fr/magistrala.html
Apache License 2.0
2.42k stars 665 forks source link

Feature: New gRPC function to list mutiple users permissions at single request #2291

Open arvindh123 opened 1 week ago

arvindh123 commented 1 week ago

Is your feature request related to a problem? Please describe.

No

Describe the feature you are requesting, as well as the possible use case(s) for it.

ListPermissionsReq gRPC can list permission for single subject.

This is used to retrieve the users permission in list endpoint. Because ListPermissionsReq gRPC can list permission only for single subject, we iterate the for users list, this leads to mutiple network calls. Instead if create new gRPC function which can list permissions for mutiple subject, the network call can be reduced. And the code will be like

    if pm.ListPerms && len(usersPage.Clients) > 0 && pm.EntityType != "" && pm.EntityID != "" {
-       g, gctx := errgroup.WithContext(ctx)
-       for i := range usersPage.Clients {
-           // Copying loop variable "i" to avoid "loop variable captured by func literal"
-           iter := i
-           g.Go(func() error {
-               return svc.retrieveObjectUsersPermissions(gctx, res.GetDomainId(), pm.EntityType, pm.EntityID, &usersPage.Clients[iter])
-           })
-       }

-       if err := g.Wait(); err != nil {
-           gctx.Done()
-           return mgclients.ClientsPage{}, err
-       }
+             usersIDs := []string{}
+       for _, client := range usersPage.Clients {
+           userIDs = append(userIDs, client.ID)
+       }
+             
+             svc.agent.ListPermissionsOfMutipleSubjects(ctx,  &magistrala.ListPermissionsOfMutipleSubjects{
+           SubjectType: auth.UserType,
+           Subjects:     userIDs,
+           Object:      objectID,
+                  ObjectType:  objectType,
+          }
    }

Indicate the importance of this feature to you.

Must-have

Anything else?

No response