Skip to content

Commit 725bd1a

Browse files
committed
refactor: migrate permissions from user_temp to member table
1 parent 790894a commit 725bd1a

17 files changed

+897
-876
lines changed

apps/dokploy/drizzle/0066_yielding_echo.sql

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@ CREATE TABLE "user_temp" (
55
"isRegistered" boolean DEFAULT false NOT NULL,
66
"expirationDate" text NOT NULL,
77
"createdAt" text NOT NULL,
8-
"canCreateProjects" boolean DEFAULT false NOT NULL,
9-
"canAccessToSSHKeys" boolean DEFAULT false NOT NULL,
10-
"canCreateServices" boolean DEFAULT false NOT NULL,
11-
"canDeleteProjects" boolean DEFAULT false NOT NULL,
12-
"canDeleteServices" boolean DEFAULT false NOT NULL,
13-
"canAccessToDocker" boolean DEFAULT false NOT NULL,
14-
"canAccessToAPI" boolean DEFAULT false NOT NULL,
15-
"canAccessToGitProviders" boolean DEFAULT false NOT NULL,
16-
"canAccessToTraefikFiles" boolean DEFAULT false NOT NULL,
17-
"accesedProjects" text[] DEFAULT ARRAY[]::text[] NOT NULL,
18-
"accesedServices" text[] DEFAULT ARRAY[]::text[] NOT NULL,
198
"two_factor_enabled" boolean DEFAULT false NOT NULL,
209
"email" text NOT NULL,
2110
"email_verified" boolean NOT NULL,
@@ -92,7 +81,18 @@ CREATE TABLE "member" (
9281
"organization_id" text NOT NULL,
9382
"user_id" text NOT NULL,
9483
"role" text NOT NULL,
95-
"created_at" timestamp NOT NULL
84+
"created_at" timestamp NOT NULL,
85+
"canCreateProjects" boolean DEFAULT false NOT NULL,
86+
"canAccessToSSHKeys" boolean DEFAULT false NOT NULL,
87+
"canCreateServices" boolean DEFAULT false NOT NULL,
88+
"canDeleteProjects" boolean DEFAULT false NOT NULL,
89+
"canDeleteServices" boolean DEFAULT false NOT NULL,
90+
"canAccessToDocker" boolean DEFAULT false NOT NULL,
91+
"canAccessToAPI" boolean DEFAULT false NOT NULL,
92+
"canAccessToGitProviders" boolean DEFAULT false NOT NULL,
93+
"canAccessToTraefikFiles" boolean DEFAULT false NOT NULL,
94+
"accesedProjects" text[] DEFAULT ARRAY[]::text[] NOT NULL,
95+
"accesedServices" text[] DEFAULT ARRAY[]::text[] NOT NULL
9696
);
9797
--> statement-breakpoint
9898
CREATE TABLE "organization" (

apps/dokploy/drizzle/0067_migrate-data.sql

+48-26
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,6 @@ inserted_members AS (
109109
"updated_at",
110110
image,
111111
"createdAt",
112-
"canAccessToAPI",
113-
"canAccessToDocker",
114-
"canAccessToGitProviders",
115-
"canAccessToSSHKeys",
116-
"canAccessToTraefikFiles",
117-
"canCreateProjects",
118-
"canCreateServices",
119-
"canDeleteProjects",
120-
"canDeleteServices",
121-
"accesedProjects",
122-
"accesedServices",
123112
"expirationDate",
124113
"isRegistered"
125114
)
@@ -131,17 +120,6 @@ inserted_members AS (
131120
CURRENT_TIMESTAMP,
132121
auth.image,
133122
NOW(),
134-
COALESCE(u."canAccessToAPI", false),
135-
COALESCE(u."canAccessToDocker", false),
136-
COALESCE(u."canAccessToGitProviders", false),
137-
COALESCE(u."canAccessToSSHKeys", false),
138-
COALESCE(u."canAccessToTraefikFiles", false),
139-
COALESCE(u."canCreateProjects", false),
140-
COALESCE(u."canCreateServices", false),
141-
COALESCE(u."canDeleteProjects", false),
142-
COALESCE(u."canDeleteServices", false),
143-
COALESCE(u."accesedProjects", '{}'),
144-
COALESCE(u."accesedServices", '{}'),
145123
NOW() + INTERVAL '1 year',
146124
COALESCE(u."isRegistered", false)
147125
FROM "user" u
@@ -180,14 +158,36 @@ inserted_admin_members AS (
180158
"organization_id",
181159
"user_id",
182160
role,
183-
"created_at"
161+
"created_at",
162+
"canAccessToAPI",
163+
"canAccessToDocker",
164+
"canAccessToGitProviders",
165+
"canAccessToSSHKeys",
166+
"canAccessToTraefikFiles",
167+
"canCreateProjects",
168+
"canCreateServices",
169+
"canDeleteProjects",
170+
"canDeleteServices",
171+
"accesedProjects",
172+
"accesedServices"
184173
)
185174
SELECT
186175
gen_random_uuid(),
187176
o.id,
188177
a."adminId",
189178
'owner',
190-
NOW()
179+
NOW(),
180+
true, -- Los admins tienen todos los permisos por defecto
181+
true,
182+
true,
183+
true,
184+
true,
185+
true,
186+
true,
187+
true,
188+
true,
189+
'{}',
190+
'{}'
191191
FROM admin a
192192
JOIN inserted_orgs o ON o."owner_id" = a."adminId"
193193
RETURNING *
@@ -198,14 +198,36 @@ INSERT INTO member (
198198
"organization_id",
199199
"user_id",
200200
role,
201-
"created_at"
201+
"created_at",
202+
"canAccessToAPI",
203+
"canAccessToDocker",
204+
"canAccessToGitProviders",
205+
"canAccessToSSHKeys",
206+
"canAccessToTraefikFiles",
207+
"canCreateProjects",
208+
"canCreateServices",
209+
"canDeleteProjects",
210+
"canDeleteServices",
211+
"accesedProjects",
212+
"accesedServices"
202213
)
203214
SELECT
204215
gen_random_uuid(),
205216
o.id,
206217
u."userId",
207218
'member',
208-
NOW()
219+
NOW(),
220+
COALESCE(u."canAccessToAPI", false),
221+
COALESCE(u."canAccessToDocker", false),
222+
COALESCE(u."canAccessToGitProviders", false),
223+
COALESCE(u."canAccessToSSHKeys", false),
224+
COALESCE(u."canAccessToTraefikFiles", false),
225+
COALESCE(u."canCreateProjects", false),
226+
COALESCE(u."canCreateServices", false),
227+
COALESCE(u."canDeleteProjects", false),
228+
COALESCE(u."canDeleteServices", false),
229+
COALESCE(u."accesedProjects", '{}'),
230+
COALESCE(u."accesedServices", '{}')
209231
FROM "user" u
210232
JOIN admin a ON u."adminId" = a."adminId"
211233
JOIN inserted_orgs o ON o."owner_id" = a."adminId";

apps/dokploy/drizzle/meta/0066_snapshot.json

+77-77
Original file line numberDiff line numberDiff line change
@@ -933,83 +933,6 @@
933933
"primaryKey": false,
934934
"notNull": true
935935
},
936-
"canCreateProjects": {
937-
"name": "canCreateProjects",
938-
"type": "boolean",
939-
"primaryKey": false,
940-
"notNull": true,
941-
"default": false
942-
},
943-
"canAccessToSSHKeys": {
944-
"name": "canAccessToSSHKeys",
945-
"type": "boolean",
946-
"primaryKey": false,
947-
"notNull": true,
948-
"default": false
949-
},
950-
"canCreateServices": {
951-
"name": "canCreateServices",
952-
"type": "boolean",
953-
"primaryKey": false,
954-
"notNull": true,
955-
"default": false
956-
},
957-
"canDeleteProjects": {
958-
"name": "canDeleteProjects",
959-
"type": "boolean",
960-
"primaryKey": false,
961-
"notNull": true,
962-
"default": false
963-
},
964-
"canDeleteServices": {
965-
"name": "canDeleteServices",
966-
"type": "boolean",
967-
"primaryKey": false,
968-
"notNull": true,
969-
"default": false
970-
},
971-
"canAccessToDocker": {
972-
"name": "canAccessToDocker",
973-
"type": "boolean",
974-
"primaryKey": false,
975-
"notNull": true,
976-
"default": false
977-
},
978-
"canAccessToAPI": {
979-
"name": "canAccessToAPI",
980-
"type": "boolean",
981-
"primaryKey": false,
982-
"notNull": true,
983-
"default": false
984-
},
985-
"canAccessToGitProviders": {
986-
"name": "canAccessToGitProviders",
987-
"type": "boolean",
988-
"primaryKey": false,
989-
"notNull": true,
990-
"default": false
991-
},
992-
"canAccessToTraefikFiles": {
993-
"name": "canAccessToTraefikFiles",
994-
"type": "boolean",
995-
"primaryKey": false,
996-
"notNull": true,
997-
"default": false
998-
},
999-
"accesedProjects": {
1000-
"name": "accesedProjects",
1001-
"type": "text[]",
1002-
"primaryKey": false,
1003-
"notNull": true,
1004-
"default": "ARRAY[]::text[]"
1005-
},
1006-
"accesedServices": {
1007-
"name": "accesedServices",
1008-
"type": "text[]",
1009-
"primaryKey": false,
1010-
"notNull": true,
1011-
"default": "ARRAY[]::text[]"
1012-
},
1013936
"two_factor_enabled": {
1014937
"name": "two_factor_enabled",
1015938
"type": "boolean",
@@ -4937,6 +4860,83 @@
49374860
"type": "timestamp",
49384861
"primaryKey": false,
49394862
"notNull": true
4863+
},
4864+
"canCreateProjects": {
4865+
"name": "canCreateProjects",
4866+
"type": "boolean",
4867+
"primaryKey": false,
4868+
"notNull": true,
4869+
"default": false
4870+
},
4871+
"canAccessToSSHKeys": {
4872+
"name": "canAccessToSSHKeys",
4873+
"type": "boolean",
4874+
"primaryKey": false,
4875+
"notNull": true,
4876+
"default": false
4877+
},
4878+
"canCreateServices": {
4879+
"name": "canCreateServices",
4880+
"type": "boolean",
4881+
"primaryKey": false,
4882+
"notNull": true,
4883+
"default": false
4884+
},
4885+
"canDeleteProjects": {
4886+
"name": "canDeleteProjects",
4887+
"type": "boolean",
4888+
"primaryKey": false,
4889+
"notNull": true,
4890+
"default": false
4891+
},
4892+
"canDeleteServices": {
4893+
"name": "canDeleteServices",
4894+
"type": "boolean",
4895+
"primaryKey": false,
4896+
"notNull": true,
4897+
"default": false
4898+
},
4899+
"canAccessToDocker": {
4900+
"name": "canAccessToDocker",
4901+
"type": "boolean",
4902+
"primaryKey": false,
4903+
"notNull": true,
4904+
"default": false
4905+
},
4906+
"canAccessToAPI": {
4907+
"name": "canAccessToAPI",
4908+
"type": "boolean",
4909+
"primaryKey": false,
4910+
"notNull": true,
4911+
"default": false
4912+
},
4913+
"canAccessToGitProviders": {
4914+
"name": "canAccessToGitProviders",
4915+
"type": "boolean",
4916+
"primaryKey": false,
4917+
"notNull": true,
4918+
"default": false
4919+
},
4920+
"canAccessToTraefikFiles": {
4921+
"name": "canAccessToTraefikFiles",
4922+
"type": "boolean",
4923+
"primaryKey": false,
4924+
"notNull": true,
4925+
"default": false
4926+
},
4927+
"accesedProjects": {
4928+
"name": "accesedProjects",
4929+
"type": "text[]",
4930+
"primaryKey": false,
4931+
"notNull": true,
4932+
"default": "ARRAY[]::text[]"
4933+
},
4934+
"accesedServices": {
4935+
"name": "accesedServices",
4936+
"type": "text[]",
4937+
"primaryKey": false,
4938+
"notNull": true,
4939+
"default": "ARRAY[]::text[]"
49404940
}
49414941
},
49424942
"indexes": {},

0 commit comments

Comments
 (0)