Add role service to options

This commit is contained in:
Benedikt Kulmann
2020-08-28 16:26:15 +02:00
parent 6196775f7d
commit 97e4450102
2 changed files with 18 additions and 6 deletions
+11 -2
View File
@@ -3,6 +3,7 @@ package service
import (
"github.com/owncloud/ocis-accounts/pkg/config"
"github.com/owncloud/ocis-pkg/v2/log"
settings "github.com/owncloud/ocis-settings/pkg/proto/v0"
)
// Option defines a single option function.
@@ -10,8 +11,9 @@ type Option func(o *Options)
// Options defines the available options for this package.
type Options struct {
Logger log.Logger
Config *config.Config
Logger log.Logger
Config *config.Config
RoleService settings.RoleService
}
func newOptions(opts ...Option) Options {
@@ -37,3 +39,10 @@ func Config(val *config.Config) Option {
o.Config = val
}
}
// RoleService provides a function to set the role service option.
func RoleService(val settings.RoleService) Option {
return func(o *Options) {
o.RoleService = val
}
}
+7 -4
View File
@@ -31,6 +31,10 @@ func New(opts ...Option) (s *Service, err error) {
options := newOptions(opts...)
logger := options.Logger
cfg := options.Config
roleService := options.RoleService
if roleService == nil {
roleService = settings.NewRoleService("com.owncloud.api.settings", mgrpc.NewClient())
}
// read all user and group records
accountsDir := filepath.Join(cfg.Server.AccountsDataPath, "accounts")
@@ -169,19 +173,18 @@ func New(opts ...Option) (s *Service, err error) {
}
// set role for admin users and regular users
rs := settings.NewRoleService("com.owncloud.api.settings", mgrpc.NewClient())
assignRoleToUser("058bff95-6708-4fe5-91e4-9ea3d377588b", settings_svc.BundleUUIDRoleAdmin, rs, logger)
assignRoleToUser("058bff95-6708-4fe5-91e4-9ea3d377588b", settings_svc.BundleUUIDRoleAdmin, roleService, logger)
for _, accountID := range []string{
"058bff95-6708-4fe5-91e4-9ea3d377588b",//moss
} {
assignRoleToUser(accountID, settings_svc.BundleUUIDRoleAdmin, rs, logger)
assignRoleToUser(accountID, settings_svc.BundleUUIDRoleAdmin, roleService, logger)
}
for _, accountID := range []string{
"4c510ada-c86b-4815-8820-42cdf82c3d51",//einstein
"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c",//marie
"932b4540-8d16-481e-8ef4-588e4b6b151c",//richard
} {
assignRoleToUser(accountID, settings_svc.BundleUUIDRoleUser, rs, logger)
assignRoleToUser(accountID, settings_svc.BundleUUIDRoleUser, roleService, logger)
}
}
} else if !fi.IsDir() {