23
23
from app .entities .platform .crud import PlatformRepository
24
24
from app .entities .platform .model import Platform
25
25
from app .entities .platform .schemas import PlatformCreate
26
- from app .services .auth0 import auth_settings
27
- from app .services .permission import AclPrivilege
26
+ from app .services .clerk . settings import clerk_settings
27
+ from app .services .permission . schemas import AclPrivilege
28
28
29
29
max_tries = 60 * 5 # 5 minutes
30
30
wait_seconds = 3
@@ -83,8 +83,8 @@ async def create_init_data() -> int: # pragma: no cover
83
83
admin1 : User | None
84
84
manager1 : User | None
85
85
employee1 : User | None
86
- organization_a : User | None
87
- organization_b : User | None
86
+ user_client_a : User | None
87
+ user_client_b : User | None
88
88
user_verified : User | None
89
89
user_unverified : User | None
90
90
c1 : Organization | None
@@ -102,17 +102,19 @@ async def create_init_data() -> int: # pragma: no cover
102
102
platform_repo : PlatformRepository
103
103
organization_platform_repo : OrganizationPlatformRepository
104
104
105
- # first admin
105
+ # first users
106
106
async with async_session () as session :
107
107
user_repo = UserRepository (session )
108
- admin1 = await user_repo .read_by ("auth_id" , auth_settings .first_admin_auth_id )
108
+
109
+ # first admin
110
+ admin1 = await user_repo .read_by ("auth_id" , clerk_settings .first_admin_auth_id )
109
111
if not admin1 :
110
112
admin1 = await user_repo .create (
111
113
UserCreate (
112
- username = auth_settings .first_admin ,
113
- email = auth_settings .first_admin ,
114
- auth_id = auth_settings .first_admin_auth_id ,
115
- picture = auth_settings .first_admin_picture ,
114
+ username = clerk_settings .first_admin ,
115
+ email = clerk_settings .first_admin ,
116
+ auth_id = clerk_settings .first_admin_auth_id ,
117
+ picture = clerk_settings .first_admin_picture ,
116
118
is_active = True ,
117
119
is_verified = True ,
118
120
is_superuser = True ,
@@ -125,19 +127,17 @@ async def create_init_data() -> int: # pragma: no cover
125
127
)
126
128
i_count += 1
127
129
128
- # first manager
129
- async with async_session () as session :
130
- user_repo = UserRepository (session )
130
+ # first manager
131
131
manager1 = await user_repo .read_by (
132
- "auth_id" , auth_settings .first_manager_auth_id
132
+ "auth_id" , clerk_settings .first_manager_auth_id
133
133
)
134
134
if not manager1 :
135
135
manager1 = await user_repo .create (
136
136
UserCreate (
137
- username = auth_settings .first_manager ,
138
- email = auth_settings .first_manager ,
139
- auth_id = auth_settings .first_manager_auth_id ,
140
- picture = auth_settings .first_manager_picture ,
137
+ username = clerk_settings .first_manager ,
138
+ email = clerk_settings .first_manager ,
139
+ auth_id = clerk_settings .first_manager_auth_id ,
140
+ picture = clerk_settings .first_manager_picture ,
141
141
is_active = True ,
142
142
is_verified = True ,
143
143
is_superuser = False ,
@@ -150,40 +150,39 @@ async def create_init_data() -> int: # pragma: no cover
150
150
)
151
151
i_count += 1
152
152
153
- # first employee
154
- async with async_session () as session :
155
- user_repo = UserRepository (session )
153
+ # first employee
156
154
employee1 = await user_repo .read_by (
157
- "auth_id" , auth_settings .first_employee_auth_id
155
+ "auth_id" , clerk_settings .first_employee_auth_id
158
156
)
159
157
if not employee1 :
160
158
employee1 = await user_repo .create (
161
159
UserCreate (
162
- username = auth_settings .first_employee ,
163
- email = auth_settings .first_employee ,
164
- auth_id = auth_settings .first_employee_auth_id ,
165
- picture = auth_settings .first_employee_picture ,
160
+ username = clerk_settings .first_employee ,
161
+ email = clerk_settings .first_employee ,
162
+ auth_id = clerk_settings .first_employee_auth_id ,
163
+ picture = clerk_settings .first_employee_picture ,
166
164
is_active = True ,
167
165
is_verified = True ,
168
166
is_superuser = False ,
169
- scopes = [AclPrivilege ("role:user" ), AclPrivilege ("role:employee" )],
167
+ scopes = [
168
+ AclPrivilege ("role:user" ),
169
+ AclPrivilege ("role:employee" ),
170
+ ],
170
171
)
171
172
)
172
173
i_count += 1
173
174
174
- # first users that is a business organization
175
- async with async_session () as session :
176
- user_repo = UserRepository (session )
177
- organization_a = await user_repo .read_by (
178
- "auth_id" , auth_settings .first_client_a_auth_id
175
+ # first users that is a business organization
176
+ user_client_a = await user_repo .read_by (
177
+ "auth_id" , clerk_settings .first_client_a_auth_id
179
178
)
180
- if not organization_a :
181
- organization_a = await user_repo .create (
179
+ if not user_client_a :
180
+ user_client_a = await user_repo .create (
182
181
UserCreate (
183
- username = auth_settings .first_client_a ,
184
- email = auth_settings .first_client_a ,
185
- auth_id = auth_settings .first_client_a_auth_id ,
186
- picture = auth_settings .first_client_a_picture ,
182
+ username = clerk_settings .first_client_a ,
183
+ email = clerk_settings .first_client_a ,
184
+ auth_id = clerk_settings .first_client_a_auth_id ,
185
+ picture = clerk_settings .first_client_a_picture ,
187
186
is_active = True ,
188
187
is_verified = True ,
189
188
is_superuser = False ,
@@ -195,16 +194,16 @@ async def create_init_data() -> int: # pragma: no cover
195
194
)
196
195
i_count += 1
197
196
198
- organization_b = await user_repo .read_by (
199
- "auth_id" , auth_settings .first_client_b_auth_id
197
+ user_client_b = await user_repo .read_by (
198
+ "auth_id" , clerk_settings .first_client_b_auth_id
200
199
)
201
- if not organization_b :
202
- organization_b = await user_repo .create (
200
+ if not user_client_b :
201
+ user_client_b = await user_repo .create (
203
202
UserCreate (
204
- username = auth_settings .first_client_b ,
205
- email = auth_settings .first_client_b ,
206
- auth_id = auth_settings .first_client_b_auth_id ,
207
- picture = auth_settings .first_client_b_picture ,
203
+ username = clerk_settings .first_client_b ,
204
+ email = clerk_settings .first_client_b ,
205
+ auth_id = clerk_settings .first_client_b_auth_id ,
206
+ picture = clerk_settings .first_client_b_picture ,
208
207
is_active = True ,
209
208
is_verified = True ,
210
209
is_superuser = False ,
@@ -216,44 +215,44 @@ async def create_init_data() -> int: # pragma: no cover
216
215
)
217
216
i_count += 1
218
217
219
- # first user verified
220
- async with async_session () as session :
221
- user_repo = UserRepository (session )
218
+ # first user verified
222
219
user_verified = await user_repo .read_by (
223
- "auth_id" , auth_settings .first_user_verified_auth_id
220
+ "auth_id" , clerk_settings .first_user_verified_auth_id
224
221
)
225
222
if not user_verified :
226
223
user_verified = await user_repo .create (
227
224
UserCreate (
228
- username = auth_settings .first_user_verified ,
229
- email = auth_settings .first_user_verified ,
230
- auth_id = auth_settings .first_user_verified_auth_id ,
225
+ username = clerk_settings .first_user_verified ,
226
+ email = clerk_settings .first_user_verified ,
227
+ auth_id = clerk_settings .first_user_verified_auth_id ,
231
228
picture = DB_STR_USER_PICTURE_DEFAULT ,
232
229
is_active = True ,
233
230
is_verified = True ,
234
231
is_superuser = False ,
235
- scopes = [AclPrivilege ("role:user" )],
232
+ scopes = [
233
+ AclPrivilege ("role:user" ),
234
+ ],
236
235
)
237
236
)
238
237
i_count += 1
239
238
240
- # first user unverified
241
- async with async_session () as session :
242
- user_repo = UserRepository (session )
239
+ # first user unverified
243
240
user_unverified = await user_repo .read_by (
244
- "auth_id" , auth_settings .first_user_unverified_auth_id
241
+ "auth_id" , clerk_settings .first_user_unverified_auth_id
245
242
)
246
243
if not user_unverified :
247
244
user_unverified = await user_repo .create (
248
245
UserCreate (
249
- username = auth_settings .first_user_unverified ,
250
- email = auth_settings .first_user_unverified ,
251
- auth_id = auth_settings .first_user_unverified_auth_id ,
246
+ username = clerk_settings .first_user_unverified ,
247
+ email = clerk_settings .first_user_unverified ,
248
+ auth_id = clerk_settings .first_user_unverified_auth_id ,
252
249
picture = DB_STR_USER_PICTURE_DEFAULT ,
253
250
is_active = True ,
254
251
is_verified = False ,
255
252
is_superuser = False ,
256
- scopes = [AclPrivilege ("role:user" )],
253
+ scopes = [
254
+ AclPrivilege ("role:user" ),
255
+ ],
257
256
)
258
257
)
259
258
i_count += 1
@@ -275,8 +274,6 @@ async def create_init_data() -> int: # pragma: no cover
275
274
)
276
275
i_count += 1
277
276
278
- # assign users to organization1: admin1
279
- async with async_session () as session :
280
277
user_organization_repo = UserOrganizationRepository (session )
281
278
c1_admin1 = await user_organization_repo .exists_by_fields (
282
279
{"user_id" : admin1 .id , "organization_id" : c1 .id }
@@ -327,11 +324,12 @@ async def create_init_data() -> int: # pragma: no cover
327
324
)
328
325
i_count += 1
329
326
330
- for slug , title in MASTER_PLATFORM_INDEX .items ():
331
- async with async_session () as session :
332
- platform_repo = PlatformRepository (session )
327
+ # create platforms
328
+ async with async_session () as session :
329
+ platform_repo = PlatformRepository (session )
330
+ for slug , title in MASTER_PLATFORM_INDEX .items ():
333
331
p1 = await platform_repo .exists_by_fields ({"slug" : slug , "title" : title })
334
- if not p1 :
332
+ if p1 is None :
335
333
p1 = await platform_repo .create (PlatformCreate (slug = slug , title = title ))
336
334
i_count += 1
337
335
0 commit comments