Update ParentalControls, map updated saved permissions/roles

This commit is contained in:
Daniel Supernault 2024-01-11 04:41:38 -07:00
parent 2dcfc81495
commit 9d365d07f9
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
2 changed files with 45 additions and 2 deletions

View file

@ -59,9 +59,13 @@ class ParentalControlsController extends Controller
{ {
$this->authPreflight($request); $this->authPreflight($request);
$uid = $request->user()->id; $uid = $request->user()->id;
$ff = $this->requestFormFields($request);
$pc = ParentalControls::whereParentId($uid)->findOrFail($id); $pc = ParentalControls::whereParentId($uid)->findOrFail($id);
$pc->permissions = $this->requestFormFields($request); $pc->permissions = $ff;
$pc->save(); $pc->save();
$roles = UserRoleService::mapActions($pc->child_id, $ff);
UserRoles::whereUserId($pc->child_id)->update(['roles' => $roles]);
return redirect($pc->manageUrl() . '?permissions'); return redirect($pc->manageUrl() . '?permissions');
} }

View file

@ -179,7 +179,7 @@ class UserRoleService
]; ];
foreach ($map as $key => $value) { foreach ($map as $key => $value) {
if(!isset($data[$value], $data[substr($value, 1)])) { if(!isset($data[$value]) && !isset($data[substr($value, 1)])) {
$map[$key] = false; $map[$key] = false;
continue; continue;
} }
@ -188,4 +188,43 @@ class UserRoleService
return $map; return $map;
} }
public static function mapActions($id, $data = [])
{
$res = [];
$map = [
'account-force-private' => 'private',
'account-ignore-follow-requests' => 'private',
'can-view-public-feed' => 'discovery_feeds',
'can-view-network-feed' => 'discovery_feeds',
'can-view-discover' => 'discovery_feeds',
'can-view-hashtag-feed' => 'discovery_feeds',
'can-post' => 'post',
'can-comment' => 'comment',
'can-like' => 'like',
'can-share' => 'share',
'can-follow' => 'follow',
'can-make-public' => '!private',
'can-direct-message' => 'dms',
'can-use-stories' => 'story',
'can-view-sensitive' => '!hide_cw',
'can-bookmark' => 'bookmark',
'can-collections' => 'collection',
'can-federation' => 'federation',
];
foreach ($map as $key => $value) {
if(!isset($data[$value]) && !isset($data[substr($value, 1)])) {
$res[$key] = false;
continue;
}
$res[$key] = str_starts_with($value, '!') ? !$data[substr($value, 1)] : $data[$value];
}
return $res;
}
} }