mirror of
https://github.com/strapi/strapi.git
synced 2025-12-02 18:13:16 +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',
|
||||
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: {
|
||||
exists: jest.fn(() => true),
|
||||
},
|
||||
'project-settings': {
|
||||
getProjectSettings: jest.fn(() => ({ menuLogo: null })),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -45,6 +48,7 @@ describe('Admin Controller', () => {
|
||||
expect(result.data).toStrictEqual({
|
||||
uuid: 'foo',
|
||||
hasAdmin: true,
|
||||
menuLogo: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -44,8 +44,19 @@ module.exports = {
|
||||
async init() {
|
||||
const uuid = strapi.config.get('uuid', false);
|
||||
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) {
|
||||
|
||||
@ -7,6 +7,20 @@ module.exports = [
|
||||
handler: 'admin.init',
|
||||
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',
|
||||
path: '/project-settings',
|
||||
|
||||
@ -4,6 +4,9 @@ const fs = require('fs');
|
||||
const { pick } = require('lodash');
|
||||
|
||||
const PROJECT_SETTINGS_FILE_INPUTS = ['menuLogo'];
|
||||
const DEFAULT_PROJECT_SETTINGS = {
|
||||
menuLogo: null,
|
||||
};
|
||||
|
||||
const parseFilesData = async files => {
|
||||
const formatedFilesData = {};
|
||||
@ -52,7 +55,10 @@ const parseFilesData = async files => {
|
||||
|
||||
const getProjectSettings = async () => {
|
||||
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
|
||||
PROJECT_SETTINGS_FILE_INPUTS.forEach(inputName => {
|
||||
@ -85,6 +91,11 @@ const uploadFiles = async (files = {}) => {
|
||||
const deleteOldFiles = async ({ previousSettings, newSettings }) => {
|
||||
return Promise.all(
|
||||
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
|
||||
if (!previousSettings[inputName]) {
|
||||
return;
|
||||
|
||||
@ -335,6 +335,12 @@ describe('Role CRUD End to End', () => {
|
||||
"displayName": "Access the marketplace",
|
||||
"subCategory": "marketplace",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::project-settings.read",
|
||||
"category": "project",
|
||||
"displayName": "Read the project level settings",
|
||||
"subCategory": "general",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::project-settings.update",
|
||||
"category": "project",
|
||||
@ -820,6 +826,12 @@ describe('Role CRUD End to End', () => {
|
||||
"displayName": "Access the marketplace",
|
||||
"subCategory": "marketplace",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::project-settings.read",
|
||||
"category": "project",
|
||||
"displayName": "Read the project level settings",
|
||||
"subCategory": "general",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::project-settings.update",
|
||||
"category": "project",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user