feat(menu-logo): added GET /project-settings route

This commit is contained in:
vincentbpro 2022-04-20 15:52:58 +02:00
parent d4c9cbfe47
commit 4c80b3f798
3 changed files with 25 additions and 1 deletions

View File

@ -48,6 +48,10 @@ module.exports = {
return { data: { uuid, hasAdmin } }; return { data: { uuid, hasAdmin } };
}, },
async getProjectSettings() {
return getService('project-settings').getProjectSettings();
},
async updateProjectSettings(ctx) { async updateProjectSettings(ctx) {
const projectSettingsService = getService('project-settings'); const projectSettingsService = getService('project-settings');

View File

@ -7,6 +7,20 @@ module.exports = [
handler: 'admin.init', handler: 'admin.init',
config: { auth: false }, config: { auth: false },
}, },
{
method: 'GET',
path: '/project-settings',
handler: 'admin.getProjectSettings',
config: {
policies: [
'admin::isAuthenticatedAdmin',
{
name: 'admin::hasPermissions',
config: { actions: ['admin::project-settings.update'] },
},
],
},
},
{ {
method: 'POST', method: 'POST',
path: '/project-settings', path: '/project-settings',

View File

@ -4,6 +4,9 @@ const fs = require('fs');
const { pick } = require('lodash'); const { pick } = require('lodash');
const PROJECT_SETTINGS_FILE_INPUTS = ['menuLogo']; const PROJECT_SETTINGS_FILE_INPUTS = ['menuLogo'];
const DEFAULT_PROJECT_SETTINGS = {
menuLogo: null,
};
const parseFilesData = async files => { const parseFilesData = async files => {
const formatedFilesData = {}; const formatedFilesData = {};
@ -52,7 +55,10 @@ const parseFilesData = async files => {
const getProjectSettings = async () => { const getProjectSettings = async () => {
const store = strapi.store({ type: 'core', name: 'admin' }); const store = strapi.store({ type: 'core', name: 'admin' });
const projectSettings = await store.get({ key: 'project-settings' }); const projectSettings = {
...DEFAULT_PROJECT_SETTINGS,
...(await store.get({ key: 'project-settings' })),
};
// Filter file input fields // Filter file input fields
PROJECT_SETTINGS_FILE_INPUTS.forEach(inputName => { PROJECT_SETTINGS_FILE_INPUTS.forEach(inputName => {