Skip to content

Commit

Permalink
Fix groups permission bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrozadotdev committed Jan 22, 2024
1 parent 2701d2d commit 1e4db9b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
9 changes: 5 additions & 4 deletions proxy/src/mocks/applications/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apps, settings, users } from "@/api";
import { apps, settings, users, groups } from "@/api";
import { ALL_USERS_GROUP_ID } from "@/constants";
import { mocker } from "@/mocker";
import {
Expand All @@ -20,6 +20,7 @@ type Permission = {

async function createPermissions(app: Application): Promise<Permission[]> {
const result: Permission[] = [];
const allGroups = await groups.list();
if (app.allUsers) {
result.push({
permissionId: `${ALL_USERS_GROUP_ID}|GROUP`,
Expand All @@ -31,13 +32,13 @@ async function createPermissions(app: Application): Promise<Permission[]> {
});
}
await Promise.all(
app.groups.map(async (g) => {
const { id, name } = typeof g === "string" ? { id: g, name: g } : g;
app.groups.map(async (id) => {
const group = allGroups.data?.find((g) => g.id === id);
result.push({
permissionId: `${id}|GROUP`,
type: "GROUP",
id,
name,
name: group?.name || id,
role: "viewer",
});
}),
Expand Down
8 changes: 4 additions & 4 deletions server/apis/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (api *applicationApi) list(c echo.Context) error {

if info.Admin == nil {
groups, err := api.dao.FindRecordsByFilter(
"_pb_groups_col_",
"users ?= \""+info.AuthRecord.Id+"\"",
"groups",
"users.id ?= \""+info.AuthRecord.Id+"\"",
"-created",
500,
0,
Expand Down Expand Up @@ -101,8 +101,8 @@ func (api *applicationApi) view(c echo.Context) error {
if info.Admin == nil {
if info.AuthRecord != nil {
groups, err := api.dao.FindRecordsByFilter(
"_pb_groups_col_",
"users ?= \""+info.AuthRecord.Id+"\"",
"groups",
"users.id ?= \""+info.AuthRecord.Id+"\"",
"-created",
500,
0,
Expand Down
12 changes: 10 additions & 2 deletions server/forms/application_upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,22 @@ func (form *ApplicationUpsert) Submit() (*models.Application, error) {
form.application.SetId(form.Id)
}

var groupsStr, usersStr string
if len(form.Groups) > 0 {
groupsStr = "\"" + strings.Join(form.Groups, "\",\"") + "\""
}
if len(form.Users) > 0 {
usersStr = "\"" + strings.Join(form.Users, "\",\"") + "\""
}

form.application.Id = form.Id
form.application.Name = form.Name
form.application.Type = form.Type
form.application.Status = form.Status
form.application.Public = form.Public
form.application.AllUsers = form.AllUsers
form.application.RawGroups = "[" + strings.Join(form.Groups, ",") + "]"
form.application.RawUsers = "[" + strings.Join(form.Users, ",") + "]"
form.application.RawGroups = "[" + groupsStr + "]"
form.application.RawUsers = "[" + usersStr + "]"
form.application.AppDsl = form.AppDsl
form.application.EditDsl = form.EditDsl

Expand Down

0 comments on commit 1e4db9b

Please sign in to comment.