Merge pull request #13163 from strapi/menu-logo/get-project-settings-routes

Menu logo/get project settings routes
This commit is contained in:
Vincent 2022-04-26 10:45:04 +02:00 committed by GitHub
commit 6c59b21e19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 2 deletions

View File

@ -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',
},
],
};

View File

@ -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,
});
});
});

View File

@ -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) {

View File

@ -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',

View File

@ -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;

View File

@ -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",