Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission names #21

Closed
VTumanov opened this issue Aug 28, 2018 · 12 comments
Closed

Permission names #21

VTumanov opened this issue Aug 28, 2018 · 12 comments
Labels
enhancement New feature or request

Comments

@VTumanov
Copy link

VTumanov commented Aug 28, 2018

Thanks, good nova module!

I see one trouble with it. If i want give readable names for permissions, i have long names in my code. And If i want give short names for better code - swears editor, because he not understand some things. Situation is aggravated when the Manager does not know english permissions names.

Maybe add a column "title" to display in the interface and a column "name" to use in the code?

@vyuldashev
Copy link
Owner

Hello, I think you should propose this feature request to spatie/laravel-permission, if they will add this, we will definitely include it in this library.

@drbyte
Copy link
Contributor

drbyte commented Aug 28, 2018

Without extending the package, you could add a layer that uses the __() translation helper.

@vyuldashev
Copy link
Owner

vyuldashev commented Aug 28, 2018

@drbyte in some projects I also create a display_name column in permissions and roles tables for such purposes. If Spatie will add it, it would be awesome

@drbyte
Copy link
Contributor

drbyte commented Aug 28, 2018

It's being considered for v3, but nothing confirmed yet.

@VTumanov
Copy link
Author

May be create own table for this and add hasOne relation? Or make your own migration for spatie permissions table, with adding title column. I think we can long wait for Spatie, if they coding v3.
This title needed only in Nova, not in other project code, so it not require "native support" from Spatie.

@vyuldashev
Copy link
Owner

I have a solution for now.

In \Vyuldashev\NovaPermission\Permission we add displayUsing call with callback which will return translation:

 Text::make(__('nova-permission-tool::permissions.name'), 'name')
    // ...
    ->displayUsing(function ($value) {
        return __('nova-permission-tool::permissions.names.' . $value);
    }),

In project's resources/lang/vendor/nova-permission-tool/en/permissions.php we add for example:

<?php

return [
    'name' => 'Name',
    'guard_name' => 'Guard Name',
    'created_at' => 'Created at',
    'updated_at' => 'Updated at',

    'names' => [
        'users-create' => 'Create Users',
    ],
];

Which will lead to this:

screen shot 2018-08-28 at 23 33 25

The same implementation can be applied for roles. If Spatie adds translatable option for permission and role names we will switch to it.

Waiting for feedback from @drbyte and @VTumanov.

@VTumanov
Copy link
Author

I think it well be more useful if use two different columns. One for Users, second for Developers, they can check permissions keys with this page.

@vyuldashev
Copy link
Owner

We can make a computed field then.

@VTumanov
Copy link
Author

Then it looks great! Thanks Bro!

@vyuldashev vyuldashev added the enhancement New feature or request label Aug 29, 2018
@vyuldashev
Copy link
Owner

@VTumanov

Just tagged v1.2.0. Check it out. You need to create in resources/lang/vendor/nova-permission-tool/en/permissions.php display_names array where key stands for permission name and value for display value. It wont show Display Name column until there is at least one value.

@VTumanov
Copy link
Author

Today i use this future, all good and work!

For other coders: in lang file you need use display_names instead names like in upper example

@drbyte
Copy link
Contributor

drbyte commented Aug 30, 2018

I think it well be more useful if use two different columns. One for Users, second for Developers, they can check permissions keys with this page.

The existing name field should be the one used "by developers", since it's the one closed to "your app code". If you need to display it differently for "users"/whatever, you can either use the translation functions or add a separate field to the db and manage that field in your own app.

meyer59 added a commit to meyer59/nova-permission that referenced this issue Dec 17, 2020
When translation key `display_names` has been set in the `resources\lang\vendor\nova-permission-tool\en\permissions.php` it show the translation only in the Permission index page. This Pr aim to show the translation also when adding/editing/showing Role's permission. This is more consistant with vyuldashev#21 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants