vsch / laravel-translation-manager

Enhanced Management of Laravel 4 & 5 Translations, with Yandex Translation API assisted translations.
MIT License
181 stars 84 forks source link

publish buttons are nowhere to be seen #137

Open vesper8 opened 6 years ago

vesper8 commented 6 years ago

Hi all! It's been a few months since I had to use the translation manager on my site, which last time I used it was working perfectly (back in April 2018). You might remember that you helped me a lot with making it work with json translations

I logged in today and in both the old interface and the new React interface, the publish buttons are nowhere to be seen.. well it's possible I'm just brainfarting and forgot about something.. but I looked everywhere and can't find them.

I guess I ran composer update since April and now I'm on version 2.6.38

Thankfully the php artisan translations:export did publish so I was still able to make my changes.. just puzzled why they aren't showing on either of the GUI interfaces

I also noticed that my ltm_user_locales table is completely empty.. could that be related?

I was able to run translations:find, execute the translations using the yandex autocomplete and export via the translations:export command, all that with an empty ltm_user_locales

Do you know why I can't publish from the GUI?

Here's some screenshots

screenshot 2018-10-20 01 10 33 screenshot 2018-10-20 01 10 11

Thanks!

vsch commented 6 years ago

@vesper8, the import and publishing buttons are only available for editors or administrators.

There is also a setting in config admin_enabled which is true by default to enable administration.

User locales table provides limits on which locales the user is allowed to modify. Being empty means that there is no limitations. The limitations are added through user administration pane in LTM.

I would check permissions code you have to allow admin/editor roles. The topic is covered in config https://github.com/vsch/laravel-translation-manager/wiki/Configuration#enabling-per-locale-user-access-control

vesper8 commented 6 years ago

ahhh.. I see what happened now

I used to have a laravel-only app, so I was using a normal login system back then. But now I switched to using laravel as an API only.. so I no longer have a dedicated login system since I use Vue with JWT now.

So what I did is I changed the "admin" middleware that was in front of the translations package and replaced it by a generic password middleware. So the route is still protected but there is no actual user logged in when I visit it

Is there a way to just completely unlock the translations and allow publishing.. even if no user is logged in?

I tried modifying the gates in my AuthServiceProvider but it looks like those only work if a user is logged in

My 'admin_enabled' is set to true.. should it be set to false in order to achieve what I want?

vsch commented 6 years ago

@vesper8, I have not tried it but have you tried to hard-code results returned by the gate functions without testing user?

vesper8 commented 6 years ago

you mean replace

return $user && $user->isAdmin();

with

return true;

?

I did try that but it didn't work

vsch commented 6 years ago

@vesper8, I looked at the Gate code in Laravel and it checks if the user is currently logged in and fails if not. So it never gets to the gate call.

    /**
     * Get the raw result from the authorization callback.
     *
     * @param  string  $ability
     * @param  array|mixed  $arguments
     * @return mixed
     */
    protected function raw($ability, $arguments = [])
    {
        if (! $user = $this->resolveUser()) {
            return false;
        }

        $arguments = Arr::wrap($arguments);

        // First we will call the "before" callbacks for the Gate. If any of these give
        // back a non-null response, we will immediately return that result in order
        // to let the developers override all checks for some authorization cases.
        $result = $this->callBeforeCallbacks(
            $user, $ability, $arguments
        );

        if (is_null($result)) {
            $result = $this->callAuthCallback($user, $ability, $arguments);
        }

        // After calling the authorization callback, we will call the "after" callbacks
        // that are registered with the Gate, which allows a developer to do logging
        // if that is required for this application. Then we'll return the result.
        $this->callAfterCallbacks(
            $user, $ability, $arguments, $result
        );

        return $result;
    }

You will need to create a dummy user for which you hard-code a log-in then the call will succeed.

vesper8 commented 6 years ago

I think I'd rather just keep using translations:export from the command line

but I think it would be nice to have a configuration option added to allow publishing without requiring users to login/register