1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-27 13:48:49 +08:00

NOISSUE - Fix listing (#1502)

Signed-off-by: Burak Sekili <buraksekili@gmail.com>
This commit is contained in:
Burak Sekili 2021-11-19 19:25:48 +03:00 committed by GitHub
parent b78928c998
commit 87510288c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -319,11 +319,19 @@ func (ts *thingsService) ListThings(ctx context.Context, token string, pm PageMe
} }
subject := res.GetId() subject := res.GetId()
// If the user is admin, fetch all things from database.
if err := ts.authorize(ctx, res.GetId(), authoritiesObject, memberRelationKey); err == nil { if err := ts.authorize(ctx, res.GetId(), authoritiesObject, memberRelationKey); err == nil {
subject = adminSubject
pm.FetchSharedThings = true pm.FetchSharedThings = true
page, err := ts.things.RetrieveAll(ctx, res.GetEmail(), pm)
if err != nil {
return Page{}, err
}
return page, err
// subject = adminSubject
} }
// If the user is not admin, check 'shared' parameter from pagemetada.
// If user provides 'shared' key, fetch things from policies.
if pm.FetchSharedThings { if pm.FetchSharedThings {
req := &mainflux.ListPoliciesReq{Act: "read", Sub: subject} req := &mainflux.ListPoliciesReq{Act: "read", Sub: subject}
lpr, err := ts.auth.ListPolicies(ctx, req) lpr, err := ts.auth.ListPolicies(ctx, req)
@ -338,6 +346,7 @@ func (ts *thingsService) ListThings(ctx context.Context, token string, pm PageMe
return page, nil return page, nil
} }
// By default, fetch things from Things service.
page, err := ts.things.RetrieveAll(ctx, res.GetEmail(), pm) page, err := ts.things.RetrieveAll(ctx, res.GetEmail(), pm)
if err != nil { if err != nil {
return Page{}, err return Page{}, err