@@ -3229,67 +3229,9 @@ class ActivityLogs(Resource):
32293229
32303230 @study_ns .doc ('list_logs' )
32313231 @require_auth (keycloak_auth )
3232+ #@require_permission('view_activity_log')
32323233 def get (self , resource_id ):
32333234 try :
3234- # Check what type of resource this is
3235- with get_db_cursor () as cursor :
3236- cursor .execute ("""
3237- SELECT id FROM projects WHERE id = %s
3238- """ , (resource_id ,))
3239- is_project = cursor .fetchone () is not None
3240-
3241- cursor .execute ("""
3242- SELECT id FROM organisations WHERE id = %s
3243- """ , (resource_id ,))
3244- is_org = cursor .fetchone () is not None
3245-
3246- cursor .execute ("""
3247- SELECT id, project_id FROM submissions WHERE id = %s
3248- """ , (resource_id ,))
3249- submission = cursor .fetchone ()
3250- is_submission = submission is not None
3251-
3252- if not is_project and not is_org and not is_submission :
3253- return {'error' : 'Resource not found' }, 404
3254-
3255- # Check permissions based on resource type
3256- user_info = extract_user_info (request .user )
3257-
3258- if is_project :
3259- has_perm , details = user_has_permission (
3260- user_info ,
3261- 'view_activity_log' ,
3262- resource_type = 'project' ,
3263- resource_id = resource_id
3264- )
3265- elif is_submission :
3266- parent_project_id = submission ['project_id' ]
3267- has_perm , details = user_has_permission (
3268- user_info ,
3269- 'view_activity_log' ,
3270- resource_type = 'project' ,
3271- resource_id = parent_project_id
3272- )
3273- else : # is_org
3274- user_org_id = user_info .get ('organisation_id' )
3275- user_roles = user_info .get ('roles' , [])
3276- is_system_admin = 'system-admin' in user_roles
3277- is_org_partial = 'agari-org-partial' in user_roles
3278-
3279- # org-partial users cannot view organization logs
3280- if is_org_partial :
3281- return {'error' : 'Permission denied. Partial members cannot view organization activity logs.' }, 403
3282-
3283- if isinstance (user_org_id , list ):
3284- has_perm = resource_id in user_org_id or is_system_admin
3285- else :
3286- has_perm = user_org_id == resource_id or is_system_admin
3287-
3288- details = {'checked' : 'organisation_membership' }
3289-
3290- if not has_perm :
3291- return {'error' : 'Permission denied' , 'details' : details }, 403
3292-
32933235 # Fetch logs with pagination
32943236 page = int (request .args .get ('page' , 1 ))
32953237 limit = min (int (request .args .get ('limit' , 10 )), 100 )
0 commit comments