Skip to content

Commit

Permalink
fixes and patches
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Oct 2, 2024
1 parent 563092d commit a9ddbe2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/Console/Commands/CreatePermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,13 @@ public function createDirectives(Model $subject, string $service, string $guard,
}

foreach ($directives as $permission => $rules) {
// dd($permission, $rules);
// role permission names can be shorthanded by excluding the service since the schema provides the service name
$permissionName = Str::startsWith($permission, $service) ? $permission : $service . ' ' . $permission;
$permissionSegmentCount = count(explode(' ', $permission));
if ($permissionSegmentCount === 3) {
$permissionName = $permission;
} else {
// role permission names can be shorthanded by excluding the service since the schema provides the service name
$permissionName = Str::startsWith($permission, $service) ? $permission : $service . ' ' . $permission;
}

// next we validate the permission name
$permissionNameSegmentsCount = count(explode(' ', $permissionName));
Expand Down Expand Up @@ -404,8 +408,14 @@ public function createDirectives(Model $subject, string $service, string $guard,
public function assignPermissions(Model $subject, string $service, string $guard, array $permissions = []): Model
{
foreach ($permissions as $permissionName) {
// role permission names can be shorthanded by excluding the service since the schema provides the service name
$permissionName = Str::startsWith($permissionName, $service) ? $permissionName : $service . ' ' . $permissionName;
$permissionSegmentCount = count(explode(' ', $permissionName));
if ($permissionSegmentCount === 3) {
$permissionName = $permissionName;
} else {
// role permission names can be shorthanded by excluding the service since the schema provides the service name
$permissionName = Str::startsWith($permissionName, $service) ? $permissionName : $service . ' ' . $permissionName;
}

// next we validate the permission name
$permissionNameSegmentsCount = count(explode(' ', $permissionName));
if ($permissionNameSegmentsCount !== 3) {
Expand Down
16 changes: 15 additions & 1 deletion src/Http/Controllers/Internal/v1/LookupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public function countries(Request $request)
$query = strtolower($request->input('query', null));
$simple = $request->boolean('simple');
$columns = $request->array('columns');
$only = array_map(fn ($s) => strtolower($s), $request->array('only'));
$except = array_map(fn ($s) => strtolower($s), $request->array('except'));

$countries = Country::search($query);

Expand All @@ -141,7 +143,19 @@ function ($country) {
);
}

return response()->json($countries);
if ($only) {
$countries = $countries->filter(function ($country) use ($only) {
return in_array(strtolower(data_get($country, 'cca2')), $only);
});
}

if ($except) {
$countries = $countries->filter(function ($country) use ($except) {
return !in_array(strtolower(data_get($country, 'cca2')), $except);
});
}

return response()->json($countries->values());
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Resources/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public function toArray($request)
'role' => $this->when(Http::isInternalRequest(), new Role($this->role), null),
'policies' => $this->when(Http::isInternalRequest(), Policy::collection($this->policies), []),
'permissions' => $this->when(Http::isInternalRequest(), $this->serializePermissions($this->permissions), []),
'role_name' => $this->when(Http::isInternalRequest(), $this->role ? $this->role->name : null),
'type' => $this->type,
'locale' => $this->getLocale(),
'types' => $this->when(Http::isInternalRequest(), $this->types ?? []),
'company_name' => $this->when(Http::isInternalRequest(), $this->company_name),
'session_status' => $this->when(Http::isInternalRequest(), $this->session_status),
'is_admin' => $this->when(Http::isInternalRequest(), $this->is_admin),
'is_online' => $this->is_online,
'date_of_birth' => $this->date_of_birth,
'last_seen_at' => $this->last_seen_at,
'last_login' => $this->last_login,
'updated_at' => $this->updated_at,
Expand Down
10 changes: 10 additions & 0 deletions src/Traits/HasMetaAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ public function missingMeta($key): bool
return !$this->hasMeta($key);
}

/**
* Checks if a meta-data key is missing.
*
* @param string $key key of the meta-data to check
*/
public function doesntHaveMeta($key): bool
{
return !$this->hasMeta($key);
}

/**
* Checks if a meta-data property's value is true.
*
Expand Down

0 comments on commit a9ddbe2

Please sign in to comment.