Skip to content

Commit

Permalink
Merge branch 'release/6.0.9'
Browse files Browse the repository at this point in the history
* release/6.0.9:
  fixes a path bug in #862
  • Loading branch information
austintoddj committed Oct 17, 2020
2 parents a5b5821 + d708fa5 commit 59f56c3
Show file tree
Hide file tree
Showing 10 changed files with 457 additions and 471 deletions.
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"/js/app.js": "/js/app.js?id=b4919aae3e120488696b",
"/js/app.js": "/js/app.js?id=c0acc0e71985702efadd",
"/css/app.css": "/css/app.css?id=08bd22e9b4628a5ecd91",
"/js/app.js.map": "/js/app.js.map?id=d9b59460acb1450b73dd",
"/js/app.js.map": "/js/app.js.map?id=24b940d7f7b37c5a7ef0",
"/css/app.css.map": "/css/app.css.map?id=a26e3f2697987381b236"
}
10 changes: 2 additions & 8 deletions resources/js/mixins/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@ import { store } from '../store';
import axios from 'axios';

export default {
computed: {
baseDomain() {
return store.state.settings.domain || `/${store.state.settings.path}`;
},
},

methods: {
request() {
let instance = axios.create();

instance.defaults.headers.common['X-CSRF-TOKEN'] = document.head.querySelector(
'meta[name="csrf-token"]'
).content;
instance.defaults.baseURL = this.baseDomain;
instance.defaults.baseURL = store.state.settings.path;

const requestHandler = (request) => {
// Add any request modifiers...
Expand All @@ -27,7 +21,7 @@ export default {
switch (error.response.status) {
case 401:
case 405:
window.location.href = `${this.baseDomain}/logout`;
window.location.href = `${store.state.settings.path}/logout`;
break;
default:
break;
Expand Down
43 changes: 25 additions & 18 deletions resources/js/store/modules/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from 'axios';
import request from '../../mixins/request';

const initialState = {
searchIndex: [],
Expand All @@ -12,25 +12,32 @@ const actions = {
context.commit('RESET_STATE');
}

// The request here was extracted from request.js since a mixin cannot be
// pulled into a store module in the same was it is a component. The
// tradeoff here is that it will not contain error modifiers.
let baseDomain = context.rootState['settings'].domain || `/${context.rootState['settings'].path}`;

axios.get(`${baseDomain}/api/search/posts`).then(({ data }) => {
context.commit('UPDATE_INDEX', data);
});

if (context.rootGetters['settings/isAdmin']) {
axios.get(`${baseDomain}/api/search/tags`).then(({ data }) => {
context.commit('UPDATE_INDEX', data);
});
axios.get(`${baseDomain}/api/search/topics`).then(({ data }) => {
context.commit('UPDATE_INDEX', data);
});
axios.get(`${baseDomain}/api/search/users`).then(({ data }) => {
request.methods
.request()
.get('/api/search/posts')
.then(({ data }) => {
context.commit('UPDATE_INDEX', data);
});

if (context.rootGetters['settings/isAdmin']) {
request.methods
.request()
.get('/api/search/tags')
.then(({ data }) => {
context.commit('UPDATE_INDEX', data);
});
request.methods
.request()
.get('/api/search/topics')
.then(({ data }) => {
context.commit('UPDATE_INDEX', data);
});
request.methods
.request()
.get('/api/search/users')
.then(({ data }) => {
context.commit('UPDATE_INDEX', data);
});
}
},
};
Expand Down
3 changes: 1 addition & 2 deletions resources/js/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const initialState = {
languageCodes: window.Canvas.languageCodes,
maxUpload: window.Canvas.maxUpload,
path: window.Canvas.path,
domain: window.Canvas.domain,
timezone: window.Canvas.timezone,
unsplash: window.Canvas.unsplash,
user: window.Canvas.user,
Expand Down Expand Up @@ -71,7 +70,7 @@ const mutations = {
},

UPDATE_DARK_MODE(state, user) {
state.user.darkMode = user.dark_mode;
state.user.dark_mode = user.dark_mode;
},

SET_USER(state, user) {
Expand Down
10 changes: 10 additions & 0 deletions src/Canvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ public static function assetsUpToDate(): bool
return File::get($path) === File::get(__DIR__.'/../public/mix-manifest.json');
}

/**
* Return the configured public path url, prioritizing a subdomain.
*
* @return string
*/
public static function basePath(): string
{
return config('canvas.domain') ?? '/' . config('canvas.path');
}

/**
* Return the configured storage path url.
*
Expand Down
3 changes: 1 addition & 2 deletions src/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public function index(Request $request)
'config' => [
'languageCodes' => Canvas::availableLanguageCodes(),
'maxUpload' => config('canvas.upload_filesize'),
'path' => config('canvas.path'),
'domain' => config('canvas.domain'),
'path' => Canvas::basePath(),
'roles' => Canvas::availableRoles(),
'timezone' => config('app.timezone'),
'translations' => Canvas::availableTranslations($request->user('canvas')->locale),
Expand Down
7 changes: 7 additions & 0 deletions tests/CanvasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Canvas\Canvas;
use Canvas\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Env;

/**
* Class CanvasTest.
Expand Down Expand Up @@ -49,6 +50,12 @@ public function it_can_check_the_published_assets_are_up_to_date()
$this->assertSame(true, Canvas::assetsUpToDate());
}

/** @test */
public function it_can_get_the_base_path()
{
$this->assertIsString(Canvas::basePath());
}

/** @test */
public function it_can_get_the_base_storage_path()
{
Expand Down
Loading

0 comments on commit 59f56c3

Please sign in to comment.