table('permission_grants')->where($f['scope'])->whereIn('permission',$rights)->get(['user_id','permission'])->all(); $nativeFunctions=[];foreach($p['existing_native_functions_to_grant_only_in_qa'] as $g){$rows=$native->table('organization_memberships as m')->join('organization_profiles as p','p.id','=','m.profile_id')->where(['m.tenant_id'=>1,'m.user_id'=>$g['native_user_id']])->where(fn($q)=>$q->whereNull('m.expires_at')->orWhere('m.expires_at','>',now()))->pluck('p.permissions');$all=[];foreach($rows as $json)$all=[...$all,...json_decode($json,true)];foreach($g['functions'] as $function)$nativeFunctions[$g['native_user_id']][$function]=in_array($function,$all,true);} $id=$profiles['finance_review']['user_id'];$out=['passed'=>true,'new_permission_names'=>count($rights),'new_rights_already_granted'=>$existing,'additional_existing_issue_right_present'=>$host->table('permission_grants')->where($f['scope']+['user_id'=>$id,'permission'=>'service_invoices.issue'])->exists(),'native_functions_present'=>$nativeFunctions,'grants_performed'=>0,'business_commands'=>0,'cache_cleared'=>false];file_put_contents($work.'/remaining-rights-readonly.json',json_encode($out,JSON_PRETTY_PRINT));echo json_encode($out+['proof'=>$work.'/remaining-rights-readonly.json']).PHP_EOL;