refactoring:
* removed extra for loop * commenting on functions
This commit is contained in:
parent
5cb94a7820
commit
b8c2ab4cf8
|
@ -94,6 +94,8 @@ func clearSessionIfRequired(currentData, updatedData map[string]interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// updateRoles will update DB for user roles, if a role is deleted by admin
|
||||||
|
// then this function will those roles from user roles if exists
|
||||||
func updateRoles(ctx context.Context, deletedRoles []string) error {
|
func updateRoles(ctx context.Context, deletedRoles []string) error {
|
||||||
data, err := db.Provider.ListUsers(ctx, &model.Pagination{
|
data, err := db.Provider.ListUsers(ctx, &model.Pagination{
|
||||||
Limit: 1,
|
Limit: 1,
|
||||||
|
@ -111,14 +113,10 @@ func updateRoles(ctx context.Context, deletedRoles []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range allData.Users {
|
for i := range allData.Users {
|
||||||
now := time.Now().Unix()
|
roles := utils.DeleteFromArray(allData.Users[i].Roles, deletedRoles)
|
||||||
allData.Users[i].Roles = utils.DeleteFromArray(allData.Users[i].Roles, deletedRoles)
|
if len(allData.Users[i].Roles) != len(roles) {
|
||||||
allData.Users[i].UpdatedAt = &now
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range allData.Users {
|
|
||||||
updatedValues := map[string]interface{}{
|
updatedValues := map[string]interface{}{
|
||||||
"roles": strings.Join(allData.Users[i].Roles, ","),
|
"roles": strings.Join(roles, ","),
|
||||||
"updated_at": time.Now().Unix(),
|
"updated_at": time.Now().Unix(),
|
||||||
}
|
}
|
||||||
id := []string{allData.Users[i].ID}
|
id := []string{allData.Users[i].ID}
|
||||||
|
@ -127,6 +125,7 @@ func updateRoles(ctx context.Context, deletedRoles []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user