-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jkoberg <jkoberg@owncloud.com>
- Loading branch information
Showing
3 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,72 @@ | ||
package store | ||
|
||
import ( | ||
"errors" | ||
|
||
settingsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/settings/v0" | ||
"github.com/owncloud/ocis/settings/pkg/settings" | ||
"github.com/owncloud/ocis/settings/pkg/util" | ||
) | ||
|
||
// ListPermissionsByResource collects all permissions from the provided roleIDs that match the requested resource | ||
func (s *Store) ListPermissionsByResource(resource *settingsmsg.Resource, roleIDs []string) ([]*settingsmsg.Permission, error) { | ||
return nil, errors.New("not implemented") | ||
records := make([]*settingsmsg.Permission, 0) | ||
for _, roleID := range roleIDs { | ||
role, err := s.ReadBundle(roleID) | ||
if err != nil { | ||
s.Logger.Debug().Str("roleID", roleID).Msg("role not found, skipping") | ||
continue | ||
} | ||
records = append(records, extractPermissionsByResource(resource, role)...) | ||
} | ||
return records, nil | ||
} | ||
|
||
// ReadPermissionByID finds the permission in the roles, specified by the provided roleIDs | ||
func (s *Store) ReadPermissionByID(permissionID string, roleIDs []string) (*settingsmsg.Permission, error) { | ||
return nil, errors.New("not implemented") | ||
for _, roleID := range roleIDs { | ||
role, err := s.ReadBundle(roleID) | ||
if err != nil { | ||
s.Logger.Debug().Str("roleID", roleID).Msg("role not found, skipping") | ||
continue | ||
} | ||
for _, permission := range role.Settings { | ||
if permission.Id == permissionID { | ||
if value, ok := permission.Value.(*settingsmsg.Setting_PermissionValue); ok { | ||
return value.PermissionValue, nil | ||
} | ||
} | ||
} | ||
} | ||
return nil, nil | ||
} | ||
|
||
// ReadPermissionByName finds the permission in the roles, specified by the provided roleIDs | ||
func (s *Store) ReadPermissionByName(name string, roleIDs []string) (*settingsmsg.Permission, error) { | ||
return nil, errors.New("not implemented") | ||
for _, roleID := range roleIDs { | ||
role, err := s.ReadBundle(roleID) | ||
if err != nil { | ||
s.Logger.Debug().Str("roleID", roleID).Msg("role not found, skipping") | ||
continue | ||
} | ||
for _, permission := range role.Settings { | ||
if permission.Name == name { | ||
if value, ok := permission.Value.(*settingsmsg.Setting_PermissionValue); ok { | ||
return value.PermissionValue, nil | ||
} | ||
} | ||
} | ||
} | ||
return nil, settings.ErrPermissionNotFound | ||
} | ||
|
||
// extractPermissionsByResource collects all permissions from the provided role that match the requested resource | ||
func extractPermissionsByResource(resource *settingsmsg.Resource, role *settingsmsg.Bundle) []*settingsmsg.Permission { | ||
permissions := make([]*settingsmsg.Permission, 0) | ||
for _, setting := range role.Settings { | ||
if value, ok := setting.Value.(*settingsmsg.Setting_PermissionValue); ok { | ||
if util.IsResourceMatched(setting.Resource, resource) { | ||
permissions = append(permissions, value.PermissionValue) | ||
} | ||
} | ||
} | ||
return permissions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters