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

[#475] Allow services to manage their own permissions #563

Open
wants to merge 43 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f1db1ee
start defining update application role API [#516]
roberlander2 Jul 12, 2022
931a556
finish implementing update application role API, testing incomplete […
roberlander2 Jul 12, 2022
feb704a
bug fixes, better code reuse [#516]
roberlander2 Jul 13, 2022
afa7af1
update changelog, better error checking [#516]
roberlander2 Jul 13, 2022
9b650d0
added update group admin API [#518]
roberlander2 Jul 20, 2022
c8a3756
bug fixes, update changelog [#518]
roberlander2 Jul 20, 2022
cbd6173
fix update permission storage function [#542]
roberlander2 Jul 21, 2022
b70fd54
update create and update permission system API responses, bug fixes […
roberlander2 Jul 21, 2022
dc32acf
bug fixes [#542]
roberlander2 Jul 22, 2022
30c3145
update changelog [#542]
roberlander2 Jul 22, 2022
fce4650
Merge remote-tracking branch 'origin/develop' into 516-update-role-pe…
shurwit Jul 29, 2022
f403907
Merge remote-tracking branch 'origin/develop' into 518-update-group-a…
shurwit Jul 29, 2022
89de84b
merged changes from 518-update-group-admin-api
roberlander2 Aug 1, 2022
460d554
update embedded roles in groups in accounts on update role [#516]
roberlander2 Aug 1, 2022
2a52765
merged changes from 516-update-role-permissions
roberlander2 Aug 1, 2022
0e1ebd1
update embedded permissions in roles/groups in accounts [#542]
roberlander2 Aug 1, 2022
6c21035
fix empty app_org_id bug
roberlander2 Aug 1, 2022
10dacf7
merged changes from develop
roberlander2 Aug 2, 2022
be1a6ee
merged changes from develop
roberlander2 Aug 2, 2022
79e7ffd
only use WithContext collection functions
roberlander2 Aug 2, 2022
544994d
only use WithContext collection functions
roberlander2 Aug 2, 2022
ab8e863
perform transaction on missing context
roberlander2 Aug 2, 2022
9532b29
perform transaction on missing context
roberlander2 Aug 2, 2022
137ff24
remove unnecessary nil context check
roberlander2 Aug 2, 2022
bbe8b9d
merged changes from 516-update-role-permissions
roberlander2 Aug 2, 2022
f98ed91
add bbs and tps update permissions APIs, not implemented yet [#475]
roberlander2 Aug 2, 2022
d1df9c1
update API docs
roberlander2 Aug 2, 2022
2199f1a
implement update service permissions API, need to handle permission i…
roberlander2 Aug 3, 2022
4c9483b
bug fixes [#475]
roberlander2 Aug 4, 2022
8a873a7
merged changes from 542-update-permission-dependents
roberlander2 Aug 4, 2022
a3d18de
better error checking
roberlander2 Aug 4, 2022
43b3883
merged changes from 542-update-permission-dependents
roberlander2 Aug 4, 2022
f2d85c2
update permission inactive flag
roberlander2 Aug 4, 2022
f27a5a2
allow system create permission API to create self-assigning permissions
roberlander2 Aug 4, 2022
ab771c9
Merge branch '542-update-permission-dependents' into 475-services-man…
roberlander2 Aug 4, 2022
e5276f0
update assigner existence checks
roberlander2 Aug 4, 2022
c526d7f
add TPs update permissions handler [#475]
roberlander2 Aug 4, 2022
c72e4bf
add admin managed flag, allow system admins to set admin managed and …
roberlander2 Aug 4, 2022
d8312a9
change admin managed to service managed [#475]
roberlander2 Aug 5, 2022
8427b3a
update changelog
roberlander2 Aug 5, 2022
4b1c15a
fix inactive flag update
roberlander2 Aug 5, 2022
b6e3e55
merged changes from develop
roberlander2 Aug 5, 2022
302b483
only return success string, don't require description in request, onl…
roberlander2 Aug 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"filename": "core/apis.go",
"hashed_secret": "f776bc8b6836b3498c27139f23f5d64e4041af0f",
"is_verified": false,
"line_number": 169
"line_number": 170
}
],
"core/auth/apis.go": [
Expand All @@ -124,7 +124,7 @@
"filename": "core/auth/apis.go",
"hashed_secret": "4d55af37dbbb6a42088d917caa1ca25428ec42c9",
"is_verified": false,
"line_number": 1918
"line_number": 1905
}
],
"core/auth/auth.go": [
Expand All @@ -133,7 +133,7 @@
"filename": "core/auth/auth.go",
"hashed_secret": "4d55af37dbbb6a42088d917caa1ca25428ec42c9",
"is_verified": false,
"line_number": 2386
"line_number": 2335
}
],
"core/auth/auth_type_email.go": [
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Allow services to manage their own permissions [#475](https://github.com/rokwire/core-building-block/issues/475)
- Update role permissions admin API [#516](https://github.com/rokwire/core-building-block/issues/516)
- Update group admin API [#518](https://github.com/rokwire/core-building-block/issues/518)
- Allow passing nil context to WithContext storage functions [#494](https://github.com/rokwire/core-building-block/issues/494)
- Account system configs [#558](https://github.com/rokwire/core-building-block/issues/558)

### Fixed
- Update permission should change roles/groups/accounts [#542](https://github.com/rokwire/core-building-block/issues/542)
- Authorization policy comments not working [#506](https://github.com/rokwire/core-building-block/issues/506)

## [1.24.1] - 2022-07-07
Expand Down
60 changes: 45 additions & 15 deletions core/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import (
"github.com/rokwire/logging-library-go/logutils"
)

//APIs exposes to the drivers adapters access to the core functionality
// APIs exposes to the drivers adapters access to the core functionality
type APIs struct {
Services Services //expose to the drivers adapters
Administration Administration //expose to the drivers adapters
Encryption Encryption //expose to the drivers adapters
BBs BBs //expose to the drivers adapters
TPs TPs //expose to the drivers adapters
System System //expose to the drivers adapters

Auth auth.APIs //expose to the drivers auth
Expand All @@ -48,7 +49,7 @@ type APIs struct {
logger *logs.Logger
}

//Start starts the core part of the application
// Start starts the core part of the application
func (c *APIs) Start() {
c.app.start()
c.Auth.Start()
Expand All @@ -59,12 +60,12 @@ func (c *APIs) Start() {
}
}

//AddListener adds application listener
// AddListener adds application listener
func (c *APIs) AddListener(listener ApplicationListener) {
c.app.addListener(listener)
}

//GetVersion gives the service version
// GetVersion gives the service version
func (c *APIs) GetVersion() string {
return c.app.version
}
Expand Down Expand Up @@ -221,7 +222,7 @@ func (c *APIs) storeSystemData() error {
return err
}

//NewCoreAPIs creates new CoreAPIs
// NewCoreAPIs creates new CoreAPIs
func NewCoreAPIs(env string, version string, build string, storage Storage, auth auth.APIs, systemInitSettings map[string]string, logger *logs.Logger) *APIs {
//add application instance
listeners := []ApplicationListener{}
Expand All @@ -232,11 +233,12 @@ func NewCoreAPIs(env string, version string, build string, storage Storage, auth
administrationImpl := &administrationImpl{app: &application}
encryptionImpl := &encryptionImpl{app: &application}
bbsImpl := &bbsImpl{app: &application}
tpsImpl := &tpsImpl{app: &application}
systemImpl := &systemImpl{app: &application}

//+ auth
coreAPIs := APIs{Services: servicesImpl, Administration: administrationImpl, Encryption: encryptionImpl,
BBs: bbsImpl, System: systemImpl, Auth: auth, app: &application, systemAppTypeIdentifier: systemInitSettings["app_type_id"],
BBs: bbsImpl, TPs: tpsImpl, System: systemImpl, Auth: auth, app: &application, systemAppTypeIdentifier: systemInitSettings["app_type_id"],
systemAppTypeName: systemInitSettings["app_type_name"], systemAPIKey: systemInitSettings["api_key"],
systemAccountEmail: systemInitSettings["email"], systemAccountPassword: systemInitSettings["password"], logger: logger}

Expand All @@ -245,7 +247,7 @@ func NewCoreAPIs(env string, version string, build string, storage Storage, auth

///

//servicesImpl
// servicesImpl
type servicesImpl struct {
app *application
}
Expand Down Expand Up @@ -315,8 +317,12 @@ func (s *administrationImpl) AdmGetApplications(orgID string) ([]model.Applicati
return s.app.admGetApplications(orgID)
}

func (s *administrationImpl) AdmCreateAppOrgGroup(name string, permissionNames []string, rolesIDs []string, appID string, orgID string, assignerPermissions []string, system bool, l *logs.Log) (*model.AppOrgGroup, error) {
return s.app.admCreateAppOrgGroup(name, permissionNames, rolesIDs, appID, orgID, assignerPermissions, system, l)
func (s *administrationImpl) AdmCreateAppOrgGroup(name string, description string, system bool, permissionNames []string, rolesIDs []string, appID string, orgID string, assignerPermissions []string, systemClaim bool, l *logs.Log) (*model.AppOrgGroup, error) {
return s.app.admCreateAppOrgGroup(name, description, system, permissionNames, rolesIDs, appID, orgID, assignerPermissions, systemClaim, l)
}

func (s *administrationImpl) AdmUpdateAppOrgGroup(ID string, name string, description string, system bool, permissionNames []string, rolesIDs []string, appID string, orgID string, assignerPermissions []string, systemClaim bool, l *logs.Log) (*model.AppOrgGroup, error) {
return s.app.admUpdateAppOrgGroup(ID, name, description, system, permissionNames, rolesIDs, appID, orgID, assignerPermissions, systemClaim, l)
}

func (s *administrationImpl) AdmGetAppOrgGroups(appID string, orgID string) ([]model.AppOrgGroup, error) {
Expand All @@ -335,8 +341,8 @@ func (s *administrationImpl) AdmRemoveAccountsFromGroup(appID string, orgID stri
return s.app.admRemoveAccountsFromGroup(appID, orgID, groupID, accountIDs, assignerPermissions, l)
}

func (s *administrationImpl) AdmCreateAppOrgRole(name string, description string, permissionNames []string, appID string, orgID string, assignerPermissions []string, system bool, l *logs.Log) (*model.AppOrgRole, error) {
return s.app.admCreateAppOrgRole(name, description, permissionNames, appID, orgID, assignerPermissions, system, l)
func (s *administrationImpl) AdmCreateAppOrgRole(name string, description string, system bool, permissionNames []string, appID string, orgID string, assignerPermissions []string, systemClaim bool, l *logs.Log) (*model.AppOrgRole, error) {
return s.app.admCreateAppOrgRole(name, description, system, permissionNames, appID, orgID, assignerPermissions, systemClaim, l)
}

func (s *administrationImpl) AdmGetAppOrgRoles(appID string, orgID string) ([]model.AppOrgRole, error) {
Expand All @@ -347,6 +353,10 @@ func (s *administrationImpl) AdmDeleteAppOrgRole(ID string, appID string, orgID
return s.app.admDeleteAppOrgRole(ID, appID, orgID, assignerPermissions, system, l)
}

func (s *administrationImpl) AdmUpdateAppOrgRole(ID string, name string, description string, system bool, permissionNames []string, appID string, orgID string, assignerPermissions []string, systemClaim bool, l *logs.Log) (*model.AppOrgRole, error) {
return s.app.admUpdateAppOrgRole(ID, name, description, system, permissionNames, appID, orgID, assignerPermissions, systemClaim, l)
}

func (s *administrationImpl) AdmGrantPermissionsToRole(appID string, orgID string, roleID string, permissionNames []string, assignerPermissions []string, system bool, l *logs.Log) error {
return s.app.admGrantPermissionsToRole(appID, orgID, roleID, permissionNames, assignerPermissions, system, l)
}
Expand Down Expand Up @@ -425,6 +435,26 @@ func (s *bbsImpl) BBsGetTest() string {
return s.app.bbsGetTest()
}

func (s *bbsImpl) BBsUpdatePermissions(permissions []model.Permission, accountID string) ([]model.Permission, error) {
return s.app.bbsUpdatePermissions(permissions, accountID)
}

///

//tpsImpl

type tpsImpl struct {
app *application
}

func (s *tpsImpl) TPsGetTest() string {
return s.app.tpsGetTest()
}

func (s *tpsImpl) TPsUpdatePermissions(permissions []model.Permission, accountID string) ([]model.Permission, error) {
return s.app.tpsUpdatePermissions(permissions, accountID)
}

///

//systemImpl
Expand Down Expand Up @@ -473,12 +503,12 @@ func (s *systemImpl) SysGetApplications() ([]model.Application, error) {
return s.app.sysGetApplications()
}

func (s *systemImpl) SysCreatePermission(name string, description *string, serviceID *string, assigners *[]string) (*model.Permission, error) {
return s.app.sysCreatePermission(name, description, serviceID, assigners)
func (s *systemImpl) SysCreatePermission(name string, description string, serviceID string, assigners *[]string, serviceManaged bool, inactive bool) (*model.Permission, error) {
return s.app.sysCreatePermission(name, description, serviceID, assigners, serviceManaged, inactive)
}

func (s *systemImpl) SysUpdatePermission(name string, description *string, serviceID *string, assigners *[]string) (*model.Permission, error) {
return s.app.sysUpdatePermission(name, description, serviceID, assigners)
func (s *systemImpl) SysUpdatePermission(name string, description string, serviceID string, assigners *[]string, serviceManaged bool, inactive bool) (*model.Permission, error) {
return s.app.sysUpdatePermission(name, description, serviceID, assigners, serviceManaged, inactive)
}

func (s *systemImpl) SysGetAppConfigs(appTypeID string, orgID *string, versionNumbers *model.VersionNumbers) ([]model.ApplicationConfig, error) {
Expand Down
6 changes: 3 additions & 3 deletions core/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/rokwire/logging-library-go/logutils"
)

//application represents the core application code based on hexagonal architecture
// application represents the core application code based on hexagonal architecture
type application struct {
env string
version string
Expand All @@ -35,14 +35,14 @@ type application struct {
auth auth.APIs
}

//start starts the core part of the application
// start starts the core part of the application
func (app *application) start() {
//set storage listener
storageListener := StorageListener{app: app}
app.storage.RegisterStorageListener(&storageListener)
}

//addListener adds application listener
// addListener adds application listener
func (app *application) addListener(listener ApplicationListener) {
//TODO
//logs.Println("Application -> AddListener")
Expand Down
Loading