Skip to content

Commit

Permalink
Merge pull request #681 from rokwire/add-code
Browse files Browse the repository at this point in the history
Add "code" field
  • Loading branch information
petyos authored Nov 24, 2023
2 parents 44967bf + 2959042 commit 1edafb4
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
"filename": "driver/web/docs/gen/gen_types.go",
"hashed_secret": "c9739eab2dfa093cc0e450bf0ea81a43ae67b581",
"is_verified": false,
"line_number": 1796
"line_number": 1806
}
],
"driver/web/docs/resources/admin/auth/login.yaml": [
Expand Down Expand Up @@ -364,5 +364,5 @@
}
]
},
"generated_at": "2023-11-23T04:49:28Z"
"generated_at": "2023-11-24T06:43:37Z"
}
10 changes: 5 additions & 5 deletions core/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (c *APIs) storeSystemData() error {
}
newDocuments["application"] = uuid.NewString()
newAndroidAppType := model.ApplicationType{ID: uuid.NewString(), Identifier: c.systemAppTypeIdentifier, Name: c.systemAppTypeName, Versions: nil}
newSystemAdminApp := model.Application{ID: newDocuments["application"], Name: "System Admin application", MultiTenant: false, Admin: true,
newSystemAdminApp := model.Application{ID: newDocuments["application"], Name: "System Admin application", MultiTenant: false, Admin: true, Code: "",
Types: []model.ApplicationType{newAndroidAppType}, DateCreated: time.Now().UTC()}
_, err = c.app.storage.InsertApplication(context, newSystemAdminApp)
if err != nil {
Expand Down Expand Up @@ -612,12 +612,12 @@ func (s *systemImpl) SysGetOrganization(ID string) (*model.Organization, error)
return s.app.sysGetOrganization(ID)
}

func (s *systemImpl) SysCreateApplication(name string, multiTenant bool, admin bool, appTypes []model.ApplicationType) (*model.Application, error) {
return s.app.sysCreateApplication(name, multiTenant, admin, appTypes)
func (s *systemImpl) SysCreateApplication(name string, multiTenant bool, admin bool, code string, appTypes []model.ApplicationType) (*model.Application, error) {
return s.app.sysCreateApplication(name, multiTenant, admin, code, appTypes)
}

func (s *systemImpl) SysUpdateApplication(ID string, name string, multiTenant bool, admin bool, appTypes []model.ApplicationType) error {
return s.app.sysUpdateApplication(ID, name, multiTenant, admin, appTypes)
func (s *systemImpl) SysUpdateApplication(ID string, name string, multiTenant bool, admin bool, code string, appTypes []model.ApplicationType) error {
return s.app.sysUpdateApplication(ID, name, multiTenant, admin, code, appTypes)
}

func (s *systemImpl) SysGetApplication(ID string) (*model.Application, error) {
Expand Down
10 changes: 5 additions & 5 deletions core/app_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (app *application) sysGetApplication(ID string) (*model.Application, error)
return appAdm, nil
}

func (app *application) sysCreateApplication(name string, multiTenant bool, admin bool, appTypes []model.ApplicationType) (*model.Application, error) {
func (app *application) sysCreateApplication(name string, multiTenant bool, admin bool, code string, appTypes []model.ApplicationType) (*model.Application, error) {
now := time.Now()

// application
Expand All @@ -136,7 +136,7 @@ func (app *application) sysCreateApplication(name string, multiTenant bool, admi
appTypes[i].Versions[vidx].DateCreated = now
}
}
application := model.Application{ID: uuid.NewString(), Name: name, MultiTenant: multiTenant, Admin: admin,
application := model.Application{ID: uuid.NewString(), Name: name, MultiTenant: multiTenant, Admin: admin, Code: code,
Types: appTypes, DateCreated: now}

insertedApplication, err := app.storage.InsertApplication(nil, application)
Expand All @@ -146,7 +146,7 @@ func (app *application) sysCreateApplication(name string, multiTenant bool, admi
return insertedApplication, nil
}

func (app *application) sysUpdateApplication(ID string, name string, multiTenant bool, admin bool, appTypes []model.ApplicationType) error {
func (app *application) sysUpdateApplication(ID string, name string, multiTenant bool, admin bool, code string, appTypes []model.ApplicationType) error {
transaction := func(context storage.TransactionContext) error {
//1. find application
application, err := app.storage.FindApplication(context, ID)
Expand Down Expand Up @@ -185,9 +185,9 @@ func (app *application) sysUpdateApplication(ID string, name string, multiTenant
}

//3. update if app types or other application params were updated
updated = updated || (name != application.Name) || (multiTenant != application.MultiTenant) || (admin != application.Admin)
updated = updated || (name != application.Name) || (multiTenant != application.MultiTenant) || (admin != application.Admin) || (code != application.Code)
if updated {
updatedApp := model.Application{ID: application.ID, Name: name, MultiTenant: multiTenant, Admin: admin,
updatedApp := model.Application{ID: application.ID, Name: name, MultiTenant: multiTenant, Admin: admin, Code: code,
Types: appTypes, DateCreated: application.DateCreated, DateUpdated: &now}
err = app.storage.SaveApplication(context, updatedApp)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ type System interface {
SysGetOrganization(ID string) (*model.Organization, error)
SysUpdateOrganization(ID string, name string, requestType string, organizationDomains []string) error

SysCreateApplication(name string, multiTenant bool, admin bool, appTypes []model.ApplicationType) (*model.Application, error)
SysUpdateApplication(ID string, name string, multiTenant bool, admin bool, appTypes []model.ApplicationType) error
SysCreateApplication(name string, multiTenant bool, admin bool, code string, appTypes []model.ApplicationType) (*model.Application, error)
SysUpdateApplication(ID string, name string, multiTenant bool, admin bool, code string, appTypes []model.ApplicationType) error
SysGetApplication(ID string) (*model.Application, error)
SysGetApplications() ([]model.Application, error)

Expand Down
4 changes: 2 additions & 2 deletions core/model/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ type Application struct {

MultiTenant bool //safer community is multi-tenant
Admin bool //is this an admin app?

Types []ApplicationType
Code string
Types []ApplicationType

Organizations []ApplicationOrganization

Expand Down
4 changes: 2 additions & 2 deletions driven/storage/conversions_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func applicationFromStorage(item *application) model.Application {

types := applicationTypesFromStorage(item.Types)
return model.Application{ID: item.ID, Name: item.Name, MultiTenant: item.MultiTenant,
Admin: item.Admin, Types: types, DateCreated: item.DateCreated, DateUpdated: item.DateUpdated}
Admin: item.Admin, Code: item.Code, Types: types, DateCreated: item.DateCreated, DateUpdated: item.DateUpdated}
}

func applicationsFromStorage(itemsList []application) []model.Application {
Expand All @@ -44,7 +44,7 @@ func applicationsFromStorage(itemsList []application) []model.Application {
func applicationToStorage(item *model.Application) *application {
applicationTypes := applicationTypesToStorage(item.Types)

return &application{ID: item.ID, Name: item.Name, MultiTenant: item.MultiTenant, Admin: item.Admin,
return &application{ID: item.ID, Name: item.Name, MultiTenant: item.MultiTenant, Admin: item.Admin, Code: item.Code,
Types: applicationTypes, DateCreated: item.DateCreated, DateUpdated: item.DateUpdated}
}

Expand Down
5 changes: 3 additions & 2 deletions driven/storage/model_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ type application struct {
ID string `bson:"_id"`
Name string `bson:"name"`

MultiTenant bool `bson:"multi_tenant"`
Admin bool `bson:"admin"`
MultiTenant bool `bson:"multi_tenant"`
Admin bool `bson:"admin"`
Code string `bson:"code"`

Types []applicationType `bson:"types"`

Expand Down
4 changes: 2 additions & 2 deletions driver/web/apis_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ func (h SystemApisHandler) createApplication(l *logs.Log, r *http.Request, claim
appTypes = applicationTypeListFromDef(*requestData.Types)
}

_, err = h.coreAPIs.System.SysCreateApplication(requestData.Name, requestData.MultiTenant, requestData.Admin, appTypes)
_, err = h.coreAPIs.System.SysCreateApplication(requestData.Name, requestData.MultiTenant, requestData.Admin, requestData.Code, appTypes)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionCreate, model.TypeApplication, nil, err, http.StatusInternalServerError, true)
}
Expand Down Expand Up @@ -784,7 +784,7 @@ func (h SystemApisHandler) updateApplication(l *logs.Log, r *http.Request, claim
appTypes = applicationTypeListFromDef(*requestData.Types)
}

err = h.coreAPIs.System.SysUpdateApplication(ID, requestData.Name, requestData.MultiTenant, requestData.Admin, appTypes)
err = h.coreAPIs.System.SysUpdateApplication(ID, requestData.Name, requestData.MultiTenant, requestData.Admin, requestData.Code, appTypes)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionUpdate, model.TypeApplication, nil, err, http.StatusInternalServerError, true)
}
Expand Down
16 changes: 15 additions & 1 deletion driver/web/conversions_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,25 @@ import (
"core-building-block/utils"
)

// PartialApp
func partialAppToDef(item model.Application) Def.PartialApp {

return Def.PartialApp{Id: &item.ID, Name: item.Name, Code: item.Code}
}

func partialAppsToDef(item []model.Application) []Def.PartialApp {
result := make([]Def.PartialApp, len(item))
for i, item := range item {
result[i] = partialAppToDef(item)
}
return result
}

// Application
func applicationToDef(item model.Application) Def.Application {
types := applicationTypeListToDef(item.Types)

return Def.Application{Id: &item.ID, Name: item.Name, MultiTenant: item.MultiTenant,
return Def.Application{Id: &item.ID, Name: item.Name, MultiTenant: item.MultiTenant, Code: item.Code,
Admin: item.Admin, Types: &types}
}

Expand Down
22 changes: 20 additions & 2 deletions driver/web/conversions_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ func accountToDef(item model.Account) *Def.Account {
scopes = []string{}
}

return &Def.Account{Id: &item.ID, Anonymous: &item.Anonymous, System: &item.AppOrg.Organization.System, Permissions: &permissions, Roles: &roles, Groups: &groups,
//app
var as []model.Application
if item.OrgAppsMemberships != nil {
for _, a := range item.OrgAppsMemberships {
as = append(as, a.AppOrg.Application)
}
}
apps := partialAppsToDef(as)

return &Def.Account{Id: &item.ID, Apps: &apps, Anonymous: &item.Anonymous, System: &item.AppOrg.Organization.System, Permissions: &permissions, Roles: &roles, Groups: &groups,
Privacy: privacy, Verified: &item.Verified, Scopes: &scopes, AuthTypes: &authTypes, Username: username, Profile: profile, Preferences: preferences, SystemConfigs: systemConfigs,
LastLoginDate: &lastLoginDate, LastAccessTokenDate: &lastAccessTokenDate, MostRecentClientVersion: item.MostRecentClientVersion, ExternalIds: &externalIds}
}
Expand Down Expand Up @@ -117,7 +126,16 @@ func partialAccountToDef(item model.Account, params map[string]interface{}) *Def

privacy := privacyToDef(&item.Privacy)

return &Def.PartialAccount{Id: &item.ID, Anonymous: item.Anonymous, AppId: item.AppOrg.Application.ID, OrgId: item.AppOrg.Organization.ID, FirstName: item.Profile.FirstName,
//app
var as []model.Application
if item.OrgAppsMemberships != nil {
for _, a := range item.OrgAppsMemberships {
as = append(as, a.AppOrg.Application)
}
}
apps := partialAppsToDef(as)

return &Def.PartialAccount{Id: &item.ID, Apps: &apps, Anonymous: item.Anonymous, AppId: item.AppOrg.Application.ID, OrgId: item.AppOrg.Organization.ID, FirstName: item.Profile.FirstName,
LastName: item.Profile.LastName, Username: username, System: &item.AppOrg.Organization.System, Permissions: permissions, Roles: roles, Groups: groups,
Privacy: privacy, Verified: &item.Verified, Scopes: &scopes, SystemConfigs: systemConfigs, AuthTypes: authTypes, DateCreated: &dateCreated,
DateUpdated: dateUpdated, Params: paramsData, ExternalIds: &externalIds}
Expand Down
25 changes: 25 additions & 0 deletions driver/web/docs/gen/def.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5916,6 +5916,7 @@ components:
- name
- multi_tenant
- admin
- code
type: object
properties:
id:
Expand All @@ -5927,6 +5928,8 @@ components:
type: boolean
admin:
type: boolean
code:
type: string
types:
type: array
items:
Expand Down Expand Up @@ -6232,6 +6235,20 @@ components:
type: boolean
time_since_login_period:
type: integer
PartialApp:
required:
- id
- name
- code
type: object
properties:
id:
readOnly: true
type: string
name:
type: string
code:
type: string
LoginSession:
type: object
properties:
Expand Down Expand Up @@ -6601,6 +6618,10 @@ components:
type: array
items:
$ref: '#/components/schemas/AppOrgRole'
apps:
type: array
items:
$ref: '#/components/schemas/PartialApp'
groups:
type: array
items:
Expand Down Expand Up @@ -6678,6 +6699,10 @@ components:
type: array
items:
$ref: '#/components/schemas/AppOrgGroup'
apps:
type: array
items:
$ref: '#/components/schemas/PartialApp'
scopes:
type: array
items:
Expand Down
10 changes: 10 additions & 0 deletions driver/web/docs/gen/gen_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions driver/web/docs/schemas/application/Application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ required:
- name
- multi_tenant
- admin
- code
type: object
properties:
id:
Expand All @@ -14,6 +15,8 @@ properties:
type: boolean
admin:
type: boolean
code:
type: string
types:
type: array
items:
Expand Down
13 changes: 13 additions & 0 deletions driver/web/docs/schemas/application/PartialApp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
required:
- id
- name
- code
type: object
properties:
id:
readOnly: true
type: string
name:
type: string
code:
type: string
2 changes: 2 additions & 0 deletions driver/web/docs/schemas/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ InactiveExpirePolicy:
$ref: "./application/InactiveExpirePolicy.yaml"
TSLExpirePolicy:
$ref: "./application/TSLExpirePolicy.yaml"
PartialApp:
$ref: "./application/PartialApp.yaml"

# auth
LoginSession:
Expand Down
4 changes: 4 additions & 0 deletions driver/web/docs/schemas/user/Account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ properties:
type: array
items:
$ref: "../application/AppOrgRole.yaml"
apps:
type: array
items:
$ref: "../application/PartialApp.yaml"
groups:
type: array
items:
Expand Down
4 changes: 4 additions & 0 deletions driver/web/docs/schemas/user/PartialAccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ properties:
type: array
items:
$ref: "../application/AppOrgGroup.yaml"
apps:
type: array
items:
$ref: "../application/PartialApp.yaml"
scopes:
type: array
items:
Expand Down

0 comments on commit 1edafb4

Please sign in to comment.