mirror of
https://github.com/strapi/strapi.git
synced 2025-12-06 20:12:45 +00:00
Merge pull request #13163 from strapi/menu-logo/get-project-settings-routes
Menu logo/get project settings routes
This commit is contained in:
commit
6c59b21e19
@ -153,5 +153,12 @@ module.exports = {
|
|||||||
section: 'settings',
|
section: 'settings',
|
||||||
category: 'project',
|
category: 'project',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
uid: 'project-settings.read',
|
||||||
|
displayName: 'Read the project level settings',
|
||||||
|
pluginName: 'admin',
|
||||||
|
section: 'settings',
|
||||||
|
category: 'project',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@ -31,6 +31,9 @@ describe('Admin Controller', () => {
|
|||||||
user: {
|
user: {
|
||||||
exists: jest.fn(() => true),
|
exists: jest.fn(() => true),
|
||||||
},
|
},
|
||||||
|
'project-settings': {
|
||||||
|
getProjectSettings: jest.fn(() => ({ menuLogo: null })),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -45,6 +48,7 @@ describe('Admin Controller', () => {
|
|||||||
expect(result.data).toStrictEqual({
|
expect(result.data).toStrictEqual({
|
||||||
uuid: 'foo',
|
uuid: 'foo',
|
||||||
hasAdmin: true,
|
hasAdmin: true,
|
||||||
|
menuLogo: null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -44,8 +44,19 @@ module.exports = {
|
|||||||
async init() {
|
async init() {
|
||||||
const uuid = strapi.config.get('uuid', false);
|
const uuid = strapi.config.get('uuid', false);
|
||||||
const hasAdmin = await getService('user').exists();
|
const hasAdmin = await getService('user').exists();
|
||||||
|
const { menuLogo } = await getService('project-settings').getProjectSettings();
|
||||||
|
|
||||||
return { data: { uuid, hasAdmin } };
|
return {
|
||||||
|
data: {
|
||||||
|
uuid,
|
||||||
|
hasAdmin,
|
||||||
|
menuLogo: menuLogo ? menuLogo.url : null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
async getProjectSettings() {
|
||||||
|
return getService('project-settings').getProjectSettings();
|
||||||
},
|
},
|
||||||
|
|
||||||
async updateProjectSettings(ctx) {
|
async updateProjectSettings(ctx) {
|
||||||
|
|||||||
@ -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.read'] },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
path: '/project-settings',
|
path: '/project-settings',
|
||||||
|
|||||||
@ -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 => {
|
||||||
@ -85,6 +91,11 @@ const uploadFiles = async (files = {}) => {
|
|||||||
const deleteOldFiles = async ({ previousSettings, newSettings }) => {
|
const deleteOldFiles = async ({ previousSettings, newSettings }) => {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
PROJECT_SETTINGS_FILE_INPUTS.map(async inputName => {
|
PROJECT_SETTINGS_FILE_INPUTS.map(async inputName => {
|
||||||
|
// Skip if the store doesn't contain project settings
|
||||||
|
if (!previousSettings) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Skip if there was no previous file
|
// Skip if there was no previous file
|
||||||
if (!previousSettings[inputName]) {
|
if (!previousSettings[inputName]) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -335,6 +335,12 @@ describe('Role CRUD End to End', () => {
|
|||||||
"displayName": "Access the marketplace",
|
"displayName": "Access the marketplace",
|
||||||
"subCategory": "marketplace",
|
"subCategory": "marketplace",
|
||||||
},
|
},
|
||||||
|
Object {
|
||||||
|
"action": "admin::project-settings.read",
|
||||||
|
"category": "project",
|
||||||
|
"displayName": "Read the project level settings",
|
||||||
|
"subCategory": "general",
|
||||||
|
},
|
||||||
Object {
|
Object {
|
||||||
"action": "admin::project-settings.update",
|
"action": "admin::project-settings.update",
|
||||||
"category": "project",
|
"category": "project",
|
||||||
@ -820,6 +826,12 @@ describe('Role CRUD End to End', () => {
|
|||||||
"displayName": "Access the marketplace",
|
"displayName": "Access the marketplace",
|
||||||
"subCategory": "marketplace",
|
"subCategory": "marketplace",
|
||||||
},
|
},
|
||||||
|
Object {
|
||||||
|
"action": "admin::project-settings.read",
|
||||||
|
"category": "project",
|
||||||
|
"displayName": "Read the project level settings",
|
||||||
|
"subCategory": "general",
|
||||||
|
},
|
||||||
Object {
|
Object {
|
||||||
"action": "admin::project-settings.update",
|
"action": "admin::project-settings.update",
|
||||||
"category": "project",
|
"category": "project",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user