mirror of
https://github.com/strapi/strapi.git
synced 2025-11-11 15:49:50 +00:00
feat: added authLogo setting
This commit is contained in:
parent
1ffef66e64
commit
51cb73f9ee
@ -32,7 +32,7 @@ describe('Admin Controller', () => {
|
|||||||
exists: jest.fn(() => true),
|
exists: jest.fn(() => true),
|
||||||
},
|
},
|
||||||
'project-settings': {
|
'project-settings': {
|
||||||
getProjectSettings: jest.fn(() => ({ menuLogo: null })),
|
getProjectSettings: jest.fn(() => ({ menuLogo: null, authLogo: null })),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -53,6 +53,7 @@ describe('Admin Controller', () => {
|
|||||||
uuid: 'foo',
|
uuid: 'foo',
|
||||||
hasAdmin: true,
|
hasAdmin: true,
|
||||||
menuLogo: null,
|
menuLogo: null,
|
||||||
|
authLogo: null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -46,7 +46,7 @@ module.exports = {
|
|||||||
async init() {
|
async init() {
|
||||||
let uuid = strapi.config.get('uuid', false);
|
let 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();
|
const { menuLogo, authLogo } = await getService('project-settings').getProjectSettings();
|
||||||
// set to null if telemetryDisabled flag not avaialble in package.json
|
// set to null if telemetryDisabled flag not avaialble in package.json
|
||||||
const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled', null);
|
const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled', null);
|
||||||
|
|
||||||
@ -59,6 +59,7 @@ module.exports = {
|
|||||||
uuid,
|
uuid,
|
||||||
hasAdmin,
|
hasAdmin,
|
||||||
menuLogo: menuLogo ? menuLogo.url : null,
|
menuLogo: menuLogo ? menuLogo.url : null,
|
||||||
|
authLogo: authLogo ? authLogo.url : null,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@ -58,6 +58,15 @@ global.strapi = {
|
|||||||
size: 123,
|
size: 123,
|
||||||
provider: 'local',
|
provider: 'local',
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
name: 'name',
|
||||||
|
url: 'file/url',
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
ext: 'png',
|
||||||
|
size: 123,
|
||||||
|
provider: 'local',
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
set: storeSet,
|
set: storeSet,
|
||||||
}),
|
}),
|
||||||
@ -75,6 +84,12 @@ describe('Project setting', () => {
|
|||||||
name: 'file.png',
|
name: 'file.png',
|
||||||
type: 'image/png',
|
type: 'image/png',
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
size: 123,
|
||||||
|
path: '/tmp/filename_123',
|
||||||
|
name: 'file.png',
|
||||||
|
type: 'image/png',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedOutput = {
|
const expectedOutput = {
|
||||||
@ -92,6 +107,20 @@ describe('Project setting', () => {
|
|||||||
height: 100,
|
height: 100,
|
||||||
tmpPath: '/tmp/filename_123',
|
tmpPath: '/tmp/filename_123',
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
name: 'filename.png',
|
||||||
|
alternativeText: null,
|
||||||
|
caption: null,
|
||||||
|
hash: 'filename_123',
|
||||||
|
ext: '.png',
|
||||||
|
mime: 'image/png',
|
||||||
|
provider: 'local',
|
||||||
|
size: 123,
|
||||||
|
stream: null,
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
tmpPath: '/tmp/filename_123',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const parsedFiles = await parseFilesData(files);
|
const parsedFiles = await parseFilesData(files);
|
||||||
@ -121,6 +150,14 @@ describe('Project setting', () => {
|
|||||||
ext: 'png',
|
ext: 'png',
|
||||||
size: 123,
|
size: 123,
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
name: 'name',
|
||||||
|
url: 'file/url',
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
ext: 'png',
|
||||||
|
size: 123,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(projectSettings).toStrictEqual(expectedOutput);
|
expect(projectSettings).toStrictEqual(expectedOutput);
|
||||||
@ -131,6 +168,7 @@ describe('Project setting', () => {
|
|||||||
it('Does not delete when there was no previous file', async () => {
|
it('Does not delete when there was no previous file', async () => {
|
||||||
const previousSettings = {
|
const previousSettings = {
|
||||||
menuLogo: null,
|
menuLogo: null,
|
||||||
|
authLogo: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const newSettings = {
|
const newSettings = {
|
||||||
@ -140,6 +178,12 @@ describe('Project setting', () => {
|
|||||||
type: 'image/png',
|
type: 'image/png',
|
||||||
url: 'file/url',
|
url: 'file/url',
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
size: 24085,
|
||||||
|
name: 'file.png',
|
||||||
|
type: 'image/png',
|
||||||
|
url: 'file/url',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await deleteOldFiles({ previousSettings, newSettings });
|
await deleteOldFiles({ previousSettings, newSettings });
|
||||||
@ -156,6 +200,13 @@ describe('Project setting', () => {
|
|||||||
provider: 'local',
|
provider: 'local',
|
||||||
url: 'file/url',
|
url: 'file/url',
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
size: 24085,
|
||||||
|
name: 'file.png',
|
||||||
|
type: 'image/png',
|
||||||
|
provider: 'local',
|
||||||
|
url: 'file/url',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const newSettings = previousSettings;
|
const newSettings = previousSettings;
|
||||||
@ -174,13 +225,20 @@ describe('Project setting', () => {
|
|||||||
provider: 'local',
|
provider: 'local',
|
||||||
url: 'file/url',
|
url: 'file/url',
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
size: 24085,
|
||||||
|
name: 'file.png',
|
||||||
|
type: 'image/png',
|
||||||
|
provider: 'local',
|
||||||
|
url: 'file/url',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const newSettings = { menuLogo: null };
|
const newSettings = { menuLogo: null, authLogo: null };
|
||||||
|
|
||||||
await deleteOldFiles({ previousSettings, newSettings });
|
await deleteOldFiles({ previousSettings, newSettings });
|
||||||
|
|
||||||
expect(providerDelete).toBeCalledTimes(1);
|
expect(providerDelete).toBeCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deletes when new files are uploaded', async () => {
|
it('Deletes when new files are uploaded', async () => {
|
||||||
@ -193,6 +251,14 @@ describe('Project setting', () => {
|
|||||||
url: 'file/url',
|
url: 'file/url',
|
||||||
hash: '123',
|
hash: '123',
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
size: 24085,
|
||||||
|
name: 'file.png',
|
||||||
|
type: 'image/png',
|
||||||
|
provider: 'local',
|
||||||
|
url: 'file/url',
|
||||||
|
hash: '123',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const newSettings = {
|
const newSettings = {
|
||||||
@ -200,11 +266,15 @@ describe('Project setting', () => {
|
|||||||
...previousSettings.menuLogo,
|
...previousSettings.menuLogo,
|
||||||
hash: '456',
|
hash: '456',
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
...previousSettings.menuLogo,
|
||||||
|
hash: '456',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await deleteOldFiles({ previousSettings, newSettings });
|
await deleteOldFiles({ previousSettings, newSettings });
|
||||||
|
|
||||||
expect(providerDelete).toBeCalledTimes(1);
|
expect(providerDelete).toBeCalledTimes(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -226,6 +296,20 @@ describe('Project setting', () => {
|
|||||||
tmpPath: '/tmp/filename_123',
|
tmpPath: '/tmp/filename_123',
|
||||||
url: '/uploads/filename_123.png',
|
url: '/uploads/filename_123.png',
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
name: 'filename.png',
|
||||||
|
alternativeText: null,
|
||||||
|
caption: null,
|
||||||
|
hash: 'filename_123',
|
||||||
|
ext: '.png',
|
||||||
|
mime: 'image/png',
|
||||||
|
size: 123,
|
||||||
|
stream: null,
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
tmpPath: '/tmp/filename_123',
|
||||||
|
url: '/uploads/filename_123.png',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedOutput = {
|
const expectedOutput = {
|
||||||
@ -238,6 +322,15 @@ describe('Project setting', () => {
|
|||||||
ext: '.png',
|
ext: '.png',
|
||||||
size: 123,
|
size: 123,
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
name: 'filename.png',
|
||||||
|
hash: 'filename_123',
|
||||||
|
url: '/uploads/filename_123.png',
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
ext: '.png',
|
||||||
|
size: 123,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await updateProjectSettings({ ...body, ...files });
|
await updateProjectSettings({ ...body, ...files });
|
||||||
@ -250,11 +343,12 @@ describe('Project setting', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Updates the project settings (delete)', async () => {
|
it('Updates the project settings (delete)', async () => {
|
||||||
const body = { menuLogo: '' };
|
const body = { menuLogo: '', authLogo: '' };
|
||||||
const files = {};
|
const files = {};
|
||||||
|
|
||||||
const expectedOutput = {
|
const expectedOutput = {
|
||||||
menuLogo: null,
|
menuLogo: null,
|
||||||
|
authLogo: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
await updateProjectSettings({ ...body, ...files });
|
await updateProjectSettings({ ...body, ...files });
|
||||||
@ -280,6 +374,15 @@ describe('Project setting', () => {
|
|||||||
size: 123,
|
size: 123,
|
||||||
provider: 'local',
|
provider: 'local',
|
||||||
},
|
},
|
||||||
|
authLogo: {
|
||||||
|
name: 'name',
|
||||||
|
url: 'file/url',
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
ext: 'png',
|
||||||
|
size: 123,
|
||||||
|
provider: 'local',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await updateProjectSettings({ ...body, ...files });
|
await updateProjectSettings({ ...body, ...files });
|
||||||
|
|||||||
@ -3,10 +3,7 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { pick } = require('lodash');
|
const { pick } = require('lodash');
|
||||||
|
|
||||||
const PROJECT_SETTINGS_FILE_INPUTS = ['menuLogo'];
|
const PROJECT_SETTINGS_FILE_INPUTS = ['menuLogo', 'authLogo'];
|
||||||
const DEFAULT_PROJECT_SETTINGS = {
|
|
||||||
menuLogo: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
const parseFilesData = async (files) => {
|
const parseFilesData = async (files) => {
|
||||||
const formatedFilesData = {};
|
const formatedFilesData = {};
|
||||||
@ -52,8 +49,15 @@ 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' });
|
||||||
|
|
||||||
|
// Returns an object with file inputs names as key and null as value
|
||||||
|
const defaultProjectSettings = PROJECT_SETTINGS_FILE_INPUTS.reduce((prev, cur) => {
|
||||||
|
prev[cur] = null;
|
||||||
|
return prev;
|
||||||
|
}, {});
|
||||||
|
|
||||||
const projectSettings = {
|
const projectSettings = {
|
||||||
...DEFAULT_PROJECT_SETTINGS,
|
...defaultProjectSettings,
|
||||||
...(await store.get({ key: 'project-settings' })),
|
...(await store.get({ key: 'project-settings' })),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -10,26 +10,35 @@ const ALLOWED_IMAGE_FILE_TYPES = ['image/jpeg', 'image/png', 'image/svg+xml'];
|
|||||||
const updateProjectSettings = yup
|
const updateProjectSettings = yup
|
||||||
.object({
|
.object({
|
||||||
menuLogo: yup.string(),
|
menuLogo: yup.string(),
|
||||||
|
authLogo: yup.string(),
|
||||||
})
|
})
|
||||||
.noUnknown();
|
.noUnknown();
|
||||||
|
|
||||||
|
const updateProjectSettingsLogo = yup.object({
|
||||||
|
name: yup.string(),
|
||||||
|
type: yup.string().oneOf(ALLOWED_IMAGE_FILE_TYPES),
|
||||||
|
size: yup.number().max(MAX_IMAGE_FILE_SIZE),
|
||||||
|
});
|
||||||
|
|
||||||
const updateProjectSettingsFiles = yup
|
const updateProjectSettingsFiles = yup
|
||||||
.object({
|
.object({
|
||||||
menuLogo: yup.object({
|
menuLogo: updateProjectSettingsLogo,
|
||||||
name: yup.string(),
|
authLogo: updateProjectSettingsLogo,
|
||||||
type: yup.string().oneOf(ALLOWED_IMAGE_FILE_TYPES),
|
|
||||||
size: yup.number().max(MAX_IMAGE_FILE_SIZE),
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.noUnknown();
|
.noUnknown();
|
||||||
|
|
||||||
const updateProjectSettingsImagesDimensions = yup.object({
|
const logoDimensions = yup.object({
|
||||||
menuLogo: yup.object({
|
width: yup.number().max(MAX_IMAGE_WIDTH),
|
||||||
width: yup.number().max(MAX_IMAGE_WIDTH),
|
height: yup.number().max(MAX_IMAGE_HEIGHT),
|
||||||
height: yup.number().max(MAX_IMAGE_HEIGHT),
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const updateProjectSettingsImagesDimensions = yup
|
||||||
|
.object({
|
||||||
|
menuLogo: logoDimensions,
|
||||||
|
authLogo: logoDimensions,
|
||||||
|
})
|
||||||
|
.noUnknown();
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
validateUpdateProjectSettings: validateYupSchemaSync(updateProjectSettings),
|
validateUpdateProjectSettings: validateYupSchemaSync(updateProjectSettings),
|
||||||
validateUpdateProjectSettingsFiles: validateYupSchemaSync(updateProjectSettingsFiles),
|
validateUpdateProjectSettingsFiles: validateYupSchemaSync(updateProjectSettingsFiles),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user