Skip to content

Commit

Permalink
Fix more lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
petyos committed Nov 29, 2023
1 parent d8a9e5b commit a5e30dd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"filename": "core/auth/auth.go",
"hashed_secret": "94a7f0195bbbd2260c4e4d02b6348fbcd90b2b30",
"is_verified": false,
"line_number": 2541
"line_number": 2539
}
],
"core/auth/auth_type_email.go": [
Expand Down Expand Up @@ -364,5 +364,5 @@
}
]
},
"generated_at": "2023-11-29T09:19:08Z"
"generated_at": "2023-11-29T10:56:59Z"
}
8 changes: 3 additions & 5 deletions core/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,9 +982,8 @@ func (a *Auth) determineOperationInternal(account *model.Account, desiredAppOrgI
}
if determinedOperation == "org-sign-up" || determinedOperation == "app-sign-up" {
return determinedOperation, nil
} else {
return "", errors.New("cannot apply sign up operation")
}
return "", errors.New("cannot apply sign up operation")
}

//if the client has not specified then decide based on that if the user exists
Expand Down Expand Up @@ -1926,10 +1925,9 @@ func (a *Auth) deleteAccount(context storage.TransactionContext, account model.A
if len(allAccountApps) == len(fromAppsIDs) {
//means remove all apps => remove the whole account
return a.deleteFullAccount(context, account)
} else {
//means remove specific apps only, so unattach only them
return a.deleteAccountFromApps(context, account, fromAppsIDs)
}
//means remove specific apps only, so unattach only them
return a.deleteAccountFromApps(context, account, fromAppsIDs)
}

func (a *Auth) deleteAccountFromApps(context storage.TransactionContext, account model.Account, fromAppsIDs []string) error {
Expand Down
99 changes: 50 additions & 49 deletions driven/storage/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,65 +669,66 @@ func (m *database) constructTenantsAccountsForOrg(orgID string, accounts []accou
}

return resAccounts, nil
} else {
//we have repeatable identities for University of Illinois
}

//find all UIUC accounts
uiucAccounts, otherAccounts := m.findUIUCAccounts(accounts)
//we have repeatable identities for University of Illinois

if len(uiucAccounts) == 0 {
return nil, errors.New("no accounts for UIUC")
}
//find all UIUC accounts
uiucAccounts, otherAccounts := m.findUIUCAccounts(accounts)

//first create tenant accounts from the UIUC accounts
uiucTenantAccounts := []tenantAccount{}
for _, uiucAccount := range uiucAccounts {
newUIUCTenantAccount := m.createTenantAccount(orgID, uiucAccount)
uiucTenantAccounts = append(uiucTenantAccounts, newUIUCTenantAccount)
}
if len(uiucAccounts) == 0 {
return nil, errors.New("no accounts for UIUC")
}

//now create tenant accounts for the other accounts
currentTenantAccounts := uiucTenantAccounts
for _, otherAccount := range otherAccounts {
//for every account determine if we need to create a new tenant account or to add it to already created

foundedTenantAccounts := m.findTenantAccountsByIdentities(otherAccount.AuthTypes, currentTenantAccounts)
if len(foundedTenantAccounts) == 0 {
//it is not there so, create a new one

newCreated := m.createTenantAccount(orgID, otherAccount)
currentTenantAccounts = append(currentTenantAccounts, newCreated)
} else if len(foundedTenantAccounts) == 1 {
//it is there only once, so add it to it

updatedTenantAccount := m.addAccountToTenantAccount(otherAccount, foundedTenantAccounts[0])

//replace item
currentTenantAccounts = m.replaceItem(updatedTenantAccount, currentTenantAccounts)
} else if len(foundedTenantAccounts) == 2 {
//it is there into two accounts, so merge them first and then add it to the merged one
tenantAccount1 := foundedTenantAccounts[0]
tenantAccount2 := foundedTenantAccounts[1]
mixedTenantAccount, err := m.mixTenantAccount(tenantAccount1, tenantAccount2)
if err != nil {
return nil, err
}
//first create tenant accounts from the UIUC accounts
uiucTenantAccounts := []tenantAccount{}
for _, uiucAccount := range uiucAccounts {
newUIUCTenantAccount := m.createTenantAccount(orgID, uiucAccount)
uiucTenantAccounts = append(uiucTenantAccounts, newUIUCTenantAccount)
}

//now create tenant accounts for the other accounts
currentTenantAccounts := uiucTenantAccounts
for _, otherAccount := range otherAccounts {
//for every account determine if we need to create a new tenant account or to add it to already created

foundedTenantAccounts := m.findTenantAccountsByIdentities(otherAccount.AuthTypes, currentTenantAccounts)
if len(foundedTenantAccounts) == 0 {
//it is not there so, create a new one

//replace the two items with the mixed one
currentTenantAccounts = m.replaceMixedItems(tenantAccount1, tenantAccount2, *mixedTenantAccount, currentTenantAccounts)
newCreated := m.createTenantAccount(orgID, otherAccount)
currentTenantAccounts = append(currentTenantAccounts, newCreated)
} else if len(foundedTenantAccounts) == 1 {
//it is there only once, so add it to it

//add to the merged item
updatedTenantAccount := m.addAccountToTenantAccount(otherAccount, *mixedTenantAccount)
updatedTenantAccount := m.addAccountToTenantAccount(otherAccount, foundedTenantAccounts[0])

//replace item
currentTenantAccounts = m.replaceItem(updatedTenantAccount, currentTenantAccounts)
} else {
return nil, errors.New("we do not support more than 2 appearings")
//replace item
currentTenantAccounts = m.replaceItem(updatedTenantAccount, currentTenantAccounts)
} else if len(foundedTenantAccounts) == 2 {
//it is there into two accounts, so merge them first and then add it to the merged one
tenantAccount1 := foundedTenantAccounts[0]
tenantAccount2 := foundedTenantAccounts[1]
mixedTenantAccount, err := m.mixTenantAccount(tenantAccount1, tenantAccount2)
if err != nil {
return nil, err
}
}

return currentTenantAccounts, nil
//replace the two items with the mixed one
currentTenantAccounts = m.replaceMixedItems(tenantAccount1, tenantAccount2, *mixedTenantAccount, currentTenantAccounts)

//add to the merged item
updatedTenantAccount := m.addAccountToTenantAccount(otherAccount, *mixedTenantAccount)

//replace item
currentTenantAccounts = m.replaceItem(updatedTenantAccount, currentTenantAccounts)
} else {
return nil, errors.New("we do not support more than 2 appearings")
}
}

return currentTenantAccounts, nil

}

func (m *database) replaceMixedItems(item1 tenantAccount, item2 tenantAccount, mixedItem tenantAccount, list []tenantAccount) []tenantAccount {
Expand Down

0 comments on commit a5e30dd

Please sign in to comment.