@@ -3173,67 +3173,9 @@ class ActivityLogs(Resource):
31733173
31743174 @study_ns .doc ('list_logs' )
31753175 @require_auth (keycloak_auth )
3176+ #@require_permission('view_activity_log')
31763177 def get (self , resource_id ):
31773178 try :
3178- # Check what type of resource this is
3179- with get_db_cursor () as cursor :
3180- cursor .execute ("""
3181- SELECT id FROM projects WHERE id = %s
3182- """ , (resource_id ,))
3183- is_project = cursor .fetchone () is not None
3184-
3185- cursor .execute ("""
3186- SELECT id FROM organisations WHERE id = %s
3187- """ , (resource_id ,))
3188- is_org = cursor .fetchone () is not None
3189-
3190- cursor .execute ("""
3191- SELECT id, project_id FROM submissions WHERE id = %s
3192- """ , (resource_id ,))
3193- submission = cursor .fetchone ()
3194- is_submission = submission is not None
3195-
3196- if not is_project and not is_org and not is_submission :
3197- return {'error' : 'Resource not found' }, 404
3198-
3199- # Check permissions based on resource type
3200- user_info = extract_user_info (request .user )
3201-
3202- if is_project :
3203- has_perm , details = user_has_permission (
3204- user_info ,
3205- 'view_activity_log' ,
3206- resource_type = 'project' ,
3207- resource_id = resource_id
3208- )
3209- elif is_submission :
3210- parent_project_id = submission ['project_id' ]
3211- has_perm , details = user_has_permission (
3212- user_info ,
3213- 'view_activity_log' ,
3214- resource_type = 'project' ,
3215- resource_id = parent_project_id
3216- )
3217- else : # is_org
3218- user_org_id = user_info .get ('organisation_id' )
3219- user_roles = user_info .get ('roles' , [])
3220- is_system_admin = 'system-admin' in user_roles
3221- is_org_partial = 'agari-org-partial' in user_roles
3222-
3223- # org-partial users cannot view organization logs
3224- if is_org_partial :
3225- return {'error' : 'Permission denied. Partial members cannot view organization activity logs.' }, 403
3226-
3227- if isinstance (user_org_id , list ):
3228- has_perm = resource_id in user_org_id or is_system_admin
3229- else :
3230- has_perm = user_org_id == resource_id or is_system_admin
3231-
3232- details = {'checked' : 'organisation_membership' }
3233-
3234- if not has_perm :
3235- return {'error' : 'Permission denied' , 'details' : details }, 403
3236-
32373179 # Fetch logs with pagination
32383180 page = int (request .args .get ('page' , 1 ))
32393181 limit = min (int (request .args .get ('limit' , 10 )), 100 )
0 commit comments