@@ -218,8 +218,14 @@ async def create_environment_file(
218
218
if not env :
219
219
raise HTTPException (status_code = 404 , detail = "Environment not found" )
220
220
221
- if env .user_id != current_user .user_id :
222
- raise HTTPException (status_code = 403 , detail = "No privilege for creating the file." )
221
+ if env .is_collaborative :
222
+ group_id = env .group_id
223
+ group = db .query (Group ).filter (Group .group_id == group_id ).first ()
224
+ if not group or current_user .user_id not in group .users :
225
+ raise HTTPException (status_code = 403 , detail = "You are not a member of this group" )
226
+ else :
227
+ if env .user_id != current_user .user_id :
228
+ raise HTTPException (status_code = 403 , detail = "You are not the owner of this environment" )
223
229
224
230
env_path = f"/app/data/{ env_id } /{ file_path } "
225
231
os .makedirs (os .path .dirname (env_path ), exist_ok = True )
@@ -240,8 +246,14 @@ async def create_environment_directory(
240
246
if not env :
241
247
raise HTTPException (status_code = 404 , detail = "Environment not found" )
242
248
243
- if current_user .user_id != env .user_id :
244
- raise HTTPException (status_code = 403 , detail = "No privilege for creating the directory." )
249
+ if env .is_collaborative :
250
+ group_id = env .group_id
251
+ group = db .query (Group ).filter (Group .group_id == group_id ).first ()
252
+ if not group or current_user .user_id not in group .users :
253
+ raise HTTPException (status_code = 403 , detail = "You are not a member of this group" )
254
+ else :
255
+ if env .user_id != current_user .user_id :
256
+ raise HTTPException (status_code = 403 , detail = "You are not the owner of this environment" )
245
257
246
258
env_path = f"/app/data/{ env_id } "
247
259
directory_path = os .path .join (env_path , directory_path .lstrip ('/' ))
@@ -264,9 +276,15 @@ async def update_environment_path(
264
276
env = db .query (Environment ).filter (Environment .environment_id == env_id ).first ()
265
277
if not env :
266
278
raise HTTPException (status_code = 404 , detail = "Environment not found" )
267
-
268
- if current_user .user_id != env .user_id :
269
- raise HTTPException (status_code = 403 , detail = "No privilege for modifying the file." )
279
+
280
+ if env .is_collaborative :
281
+ group_id = env .group_id
282
+ group = db .query (Group ).filter (Group .group_id == group_id ).first ()
283
+ if not group or current_user .user_id not in group .users :
284
+ raise HTTPException (status_code = 403 , detail = "You are not a member of this group" )
285
+ else :
286
+ if env .user_id != current_user .user_id :
287
+ raise HTTPException (status_code = 403 , detail = "You are not the owner of this environment" )
270
288
271
289
env_path = f"/app/data/{ env_id } "
272
290
origin_path = os .path .join (env_path , from_uri .lstrip ('/' ))
@@ -304,8 +322,14 @@ async def delete_environment_path(
304
322
if not env :
305
323
raise HTTPException (status_code = 404 , detail = "Environment not found" )
306
324
307
- if current_user .user_id != env .user_id :
308
- raise HTTPException (status_code = 403 , detail = "No privilege for deleting the file." )
325
+ if env .is_collaborative :
326
+ group_id = env .group_id
327
+ group = db .query (Group ).filter (Group .group_id == group_id ).first ()
328
+ if not group or current_user .user_id not in group .users :
329
+ raise HTTPException (status_code = 403 , detail = "You are not a member of this group" )
330
+ else :
331
+ if env .user_id != current_user .user_id :
332
+ raise HTTPException (status_code = 403 , detail = "You are not the owner of this environment" )
309
333
310
334
env_path = f"/app/data/{ env_id } "
311
335
file_path = os .path .join (env_path , uri .lstrip ('/' ))
0 commit comments