Skip to content

Commit

Permalink
feat: allow the hiding of abilities from UI
Browse files Browse the repository at this point in the history
adds the ability to hide the abilities from the UI.

Resolves #25
  • Loading branch information
Jeff Beltran committed Feb 7, 2021
1 parent 8e4aa21 commit 068f774
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
26 changes: 24 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ public function fields(Request $request)

```

## Other Info
## Features

This is super basic plugin at the moment, I just needed a quick way to generate a Sanctum token from Nova. This does not allow or support other features that Sanctum does, however ,if there is a want/need from other people i'll get more functionality added.
### Hide Abilities

You can hide the reference to the token abilities from the UI by calling the `hideAbilities()` method on the field.

```php
use Jeffbeltran\SanctumTokens\SanctumTokens;

/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
ID::make('ID', 'id')->sortable(),
...
SanctumTokens::make()->hideAbilities(),
];
}

```
8 changes: 7 additions & 1 deletion resources/js/components/CreateToken.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<div class="help-text help-text mt-2"></div>
</div>
</div>
<div class="flex w-full">
<div class="flex w-full" v-if="showAbilities">
<div class="w-1/5 px-8 py-6">
<label
for="scopes"
Expand Down Expand Up @@ -71,6 +71,12 @@

<script>
export default {
props: {
showAbilities: {
required: true,
type: Boolean,
},
},
/**
* Mount the component.
*/
Expand Down
6 changes: 5 additions & 1 deletion resources/js/components/Token.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<span class="whitespace-no-wrap">{{ token.name }}</span>
</div>
</td>
<td>
<td v-if="showAbilities">
<div class="text-left text-left" via-resource="users" via-resource-id="1">
<span class="whitespace-no-wrap">{{ token.abilities }}</span>
</div>
Expand Down Expand Up @@ -56,6 +56,10 @@ export default {
required: true,
type: Object,
},
showAbilities: {
required: true,
type: Boolean,
},
},
data() {
return {
Expand Down
4 changes: 3 additions & 1 deletion resources/js/components/Tool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<th class="text-left">
<span>Name</span>
</th>
<th class="text-left">
<th class="text-left" v-if="panel.options.showAbilities">
<span>Abilities</span>
</th>
<th class="text-left">
Expand All @@ -38,6 +38,7 @@
v-for="token in tokens"
:key="token.id"
:token="token"
:show-abilities="panel.options.showAbilities"
@revoke-token="revokeToken"
></token>
</tbody>
Expand Down Expand Up @@ -75,6 +76,7 @@
<portal to="modals" transition="fade-transition">
<create-token
v-if="showAddModal"
:show-abilities="panel.options.showAbilities"
@create="createToken"
@cancelled-create="closeModal"
>
Expand Down
27 changes: 27 additions & 0 deletions src/SanctumTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

class SanctumTokens extends ResourceTool
{
private $defaultOptions = ["showAbilities" => true];

public function __construct()
{
parent::__construct();

$this->meta["options"] = $this->defaultOptions;
}

/**
* Get the displayable name of the resource tool.
*
Expand All @@ -16,6 +25,24 @@ public function name()
return "Sanctum Tokens";
}

private function updateOption(array $value)
{
$this->meta["options"] = array_merge($this->meta["options"], $value);
return $this;
}

/**
* This will hide the references to abilities from the UI
*
* @return $this
*/
public function hideAbilities()
{
return $this->updateOption([
"showAbilities" => false,
]);
}

/**
* Get the component name for the resource tool.
*
Expand Down

0 comments on commit 068f774

Please sign in to comment.