Skip to content

Commit

Permalink
Merge pull request #9 from tv2regionerne/fix/csrf-expiry
Browse files Browse the repository at this point in the history
Update CSRF before checking lock status
  • Loading branch information
SylvesterDamgaard authored Feb 29, 2024
2 parents 2107c6d + a4e121a commit cba7fe4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
1 change: 0 additions & 1 deletion resources/dist/build/assets/addon-2cff5337.js

This file was deleted.

1 change: 1 addition & 0 deletions resources/dist/build/assets/addon-ec9db2e5.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion resources/dist/build/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resources/js/addon.js": {
"file": "assets/addon-2cff5337.js",
"file": "assets/addon-ec9db2e5.js",
"isEntry": true,
"src": "resources/js/addon.js"
}
Expand Down
35 changes: 22 additions & 13 deletions resources/js/components/modals/LockModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,21 @@ export default {
},
checkLockStatus() {
this.$axios.post(cp_url('statamic-locks/locks'), {
item_id: this.itemId,
item_type: this.itemType,
}).then(response => {
if (response.data.error) {
this.show = true;
this.updateCsrfToken().then(() => {
this.$axios.post(cp_url('statamic-locks/locks'), {
item_id: this.itemId,
item_type: this.itemType,
}).then(response => {
if (response.data.error) {
this.show = true;
this.status = response.data;
return;
}
this.show = false;
this.status = response.data;
return;
}
this.show = false;
this.status = response.data;
}).catch(e => this.handleAxiosError(e));
}).catch(e => this.handleAxiosError(e));
});
},
handleAxiosError(e) {
Expand All @@ -104,8 +106,15 @@ export default {
locks() {
window.location.href = cp_url('statamic-locks/locks');
}
},
updateCsrfToken() {
return this.$axios.get(cp_url('auth/token')).then(response => {
const csrf = response.data;
this.$axios.defaults.headers.common['X-CSRF-TOKEN'] = csrf;
this.$config.set('csrfToken', csrf);
});
},
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ServiceProvider extends AddonServiceProvider
protected $commands = [
ClearLocks::class,
];

protected $listen = [
Events\AssetSaving::class => [Listeners\LockListener::class],
Events\EntrySaving::class => [Listeners\LockListener::class],
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function resolveApplicationConfiguration($app)
foreach ($configs as $config) {
$app['config']->set(
"statamic.$config",
require (__DIR__."/../vendor/statamic/cms/config/{$config}.php")
require(__DIR__."/../vendor/statamic/cms/config/{$config}.php")
);
}

Expand All @@ -96,7 +96,7 @@ protected function resolveApplicationConfiguration($app)
'directory' => __DIR__.'/__fixtures__/users',
]);

$app['config']->set('statamic-locks', require (__DIR__.'/../config/statamic-locks.php'));
$app['config']->set('statamic-locks', require(__DIR__.'/../config/statamic-locks.php'));

$app['config']->set('app.debug', true);
}
Expand Down

0 comments on commit cba7fe4

Please sign in to comment.