mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 00:39:49 +00:00
Move hash function to user services instead of it being a separate service
This commit is contained in:
parent
cc17c00fd6
commit
3ead6f2487
@ -108,7 +108,7 @@ describe('Role controller', () => {
|
|||||||
role: {
|
role: {
|
||||||
findOne,
|
findOne,
|
||||||
},
|
},
|
||||||
'user-hash': {
|
user: {
|
||||||
hashAdminUser,
|
hashAdminUser,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -155,7 +155,7 @@ describe('Role controller', () => {
|
|||||||
actionProvider: { get: jest.fn() },
|
actionProvider: { get: jest.fn() },
|
||||||
conditionProvider: { values: jest.fn(() => []) },
|
conditionProvider: { values: jest.fn(() => []) },
|
||||||
},
|
},
|
||||||
'user-hash': {
|
user: {
|
||||||
hashAdminUser,
|
hashAdminUser,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -226,7 +226,7 @@ describe('Role controller', () => {
|
|||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'user-hash': {
|
user: {
|
||||||
hashAdminUser,
|
hashAdminUser,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -28,8 +28,6 @@ describe('User Controller', () => {
|
|||||||
services: {
|
services: {
|
||||||
user: {
|
user: {
|
||||||
exists,
|
exists,
|
||||||
},
|
|
||||||
'user-hash': {
|
|
||||||
hashAdminUser,
|
hashAdminUser,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -68,8 +66,6 @@ describe('User Controller', () => {
|
|||||||
exists,
|
exists,
|
||||||
create,
|
create,
|
||||||
sanitizeUser,
|
sanitizeUser,
|
||||||
},
|
|
||||||
'user-hash': {
|
|
||||||
hashAdminUser,
|
hashAdminUser,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -122,7 +122,7 @@ module.exports = {
|
|||||||
roles: superAdminRole ? [superAdminRole.id] : [],
|
roles: superAdminRole ? [superAdminRole.id] : [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const adminUserId = await getService('user-hash').hashAdminUser(user);
|
const adminUserId = await getService('user').hashAdminUser(user);
|
||||||
|
|
||||||
strapi.telemetry.send(adminUserId, 'didCreateFirstAdmin');
|
strapi.telemetry.send(adminUserId, 'didCreateFirstAdmin');
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ module.exports = {
|
|||||||
async updatePermissions(ctx) {
|
async updatePermissions(ctx) {
|
||||||
const { id } = ctx.params;
|
const { id } = ctx.params;
|
||||||
const { body: input } = ctx.request;
|
const { body: input } = ctx.request;
|
||||||
const adminUserId = await getService('user-hash').hashAdminUser(ctx.state.user);
|
const adminUserId = await getService('user').hashAdminUser(ctx.state.user);
|
||||||
|
|
||||||
const { findOne, assignPermissions } = getService('role');
|
const { findOne, assignPermissions } = getService('role');
|
||||||
const { sanitizePermission, actionProvider } = getService('permission');
|
const { sanitizePermission, actionProvider } = getService('permission');
|
||||||
|
@ -13,7 +13,7 @@ const { getService } = require('../utils');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
async create(ctx) {
|
async create(ctx) {
|
||||||
const { body } = ctx.request;
|
const { body } = ctx.request;
|
||||||
const adminUserId = await getService('user-hash').hashAdminUser(ctx.state.user);
|
const adminUserId = await getService('user').hashAdminUser(ctx.state.user);
|
||||||
|
|
||||||
await validateUserCreationInput(body);
|
await validateUserCreationInput(body);
|
||||||
|
|
||||||
|
@ -14,5 +14,4 @@ module.exports = {
|
|||||||
action: require('./action'),
|
action: require('./action'),
|
||||||
'api-token': require('./api-token'),
|
'api-token': require('./api-token'),
|
||||||
'project-settings': require('./project-settings'),
|
'project-settings': require('./project-settings'),
|
||||||
'user-hash': require('./user-hash'),
|
|
||||||
};
|
};
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const crypto = require('crypto');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
hashAdminUser(payload) {
|
|
||||||
if (typeof payload === 'string') {
|
|
||||||
return crypto.createHash('sha256').update(payload).digest('hex');
|
|
||||||
}
|
|
||||||
|
|
||||||
return crypto.createHash('sha256').update(payload.email).digest('hex');
|
|
||||||
},
|
|
||||||
};
|
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const { defaults } = require('lodash/fp');
|
const { defaults } = require('lodash/fp');
|
||||||
|
const crypto = require('crypto');
|
||||||
const { stringIncludes } = require('@strapi/utils');
|
const { stringIncludes } = require('@strapi/utils');
|
||||||
const { ValidationError } = require('@strapi/utils').errors;
|
const { ValidationError } = require('@strapi/utils').errors;
|
||||||
const { createUser, hasSuperAdminRole } = require('../domain/user');
|
const { createUser, hasSuperAdminRole } = require('../domain/user');
|
||||||
@ -323,6 +324,14 @@ const getLanguagesInUse = async () => {
|
|||||||
return users.map((user) => user.preferedLanguage || 'en');
|
return users.map((user) => user.preferedLanguage || 'en');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hashAdminUser = (payload) => {
|
||||||
|
if (typeof payload === 'string') {
|
||||||
|
return crypto.createHash('sha256').update(payload).digest('hex');
|
||||||
|
}
|
||||||
|
|
||||||
|
return crypto.createHash('sha256').update(payload.email).digest('hex');
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
create,
|
create,
|
||||||
updateById,
|
updateById,
|
||||||
@ -341,4 +350,5 @@ module.exports = {
|
|||||||
displayWarningIfUsersDontHaveRole,
|
displayWarningIfUsersDontHaveRole,
|
||||||
resetPasswordByEmail,
|
resetPasswordByEmail,
|
||||||
getLanguagesInUse,
|
getLanguagesInUse,
|
||||||
|
hashAdminUser,
|
||||||
};
|
};
|
||||||
|
@ -112,7 +112,7 @@ describe('Single Types', () => {
|
|||||||
permission: {
|
permission: {
|
||||||
createPermissionsManager,
|
createPermissionsManager,
|
||||||
},
|
},
|
||||||
'user-hash': {
|
user: {
|
||||||
hashAdminUser,
|
hashAdminUser,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -65,7 +65,7 @@ module.exports = {
|
|||||||
const { userAbility, user } = ctx.state;
|
const { userAbility, user } = ctx.state;
|
||||||
const { model } = ctx.params;
|
const { model } = ctx.params;
|
||||||
const { body } = ctx.request;
|
const { body } = ctx.request;
|
||||||
const adminUserId = strapi.service('admin::user-hash').hashAdminUser(ctx.state.user);
|
const adminUserId = strapi.service('admin::user').hashAdminUser(ctx.state.user);
|
||||||
|
|
||||||
const totalEntries = await strapi.query(model).count();
|
const totalEntries = await strapi.query(model).count();
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ module.exports = {
|
|||||||
const { userAbility } = ctx.state;
|
const { userAbility } = ctx.state;
|
||||||
const { uid } = ctx.params;
|
const { uid } = ctx.params;
|
||||||
const { body } = ctx.request;
|
const { body } = ctx.request;
|
||||||
const adminUserId = strapi.service('admin::user-hash').hashAdminUser(ctx.state.user);
|
const adminUserId = strapi.service('admin::user').hashAdminUser(ctx.state.user);
|
||||||
|
|
||||||
const contentTypeService = getService('content-types');
|
const contentTypeService = getService('content-types');
|
||||||
const metricsService = getService('metrics');
|
const metricsService = getService('metrics');
|
||||||
|
@ -46,7 +46,7 @@ module.exports = {
|
|||||||
const { user, userAbility } = ctx.state;
|
const { user, userAbility } = ctx.state;
|
||||||
const { model } = ctx.params;
|
const { model } = ctx.params;
|
||||||
const { body, query } = ctx.request;
|
const { body, query } = ctx.request;
|
||||||
const adminUserId = strapi.service('admin::user-hash').hashAdminUser(ctx.state.user);
|
const adminUserId = strapi.service('admin::user').hashAdminUser(ctx.state.user);
|
||||||
|
|
||||||
const entityManager = getService('entity-manager');
|
const entityManager = getService('entity-manager');
|
||||||
const permissionChecker = getService('permission-checker').create({ userAbility, model });
|
const permissionChecker = getService('permission-checker').create({ userAbility, model });
|
||||||
|
@ -47,7 +47,7 @@ module.exports = {
|
|||||||
|
|
||||||
async createContentType(ctx) {
|
async createContentType(ctx) {
|
||||||
const { body } = ctx.request;
|
const { body } = ctx.request;
|
||||||
const adminUserId = strapi.service('admin::user-hash').hashAdminUser(ctx.state.user);
|
const adminUserId = strapi.service('admin::user').hashAdminUser(ctx.state.user);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await validateContentTypeInput(body);
|
await validateContentTypeInput(body);
|
||||||
|
@ -16,7 +16,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await validateSettings(body);
|
const data = await validateSettings(body);
|
||||||
const adminUserId = strapi.service('admin::user-hash').hashAdminUser(ctx.state.user.email);
|
const adminUserId = strapi.service('admin::user').hashAdminUser(ctx.state.user.email);
|
||||||
|
|
||||||
await getService('upload').setSettings(data, adminUserId);
|
await getService('upload').setSettings(data, adminUserId);
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ module.exports = {
|
|||||||
id
|
id
|
||||||
);
|
);
|
||||||
|
|
||||||
user.adminUserId = strapi.service('admin::user-hash').hashAdminUser(user);
|
user.adminUserId = strapi.service('admin::user').hashAdminUser(user);
|
||||||
|
|
||||||
const data = await validateUploadBody(body);
|
const data = await validateUploadBody(body);
|
||||||
const file = await uploadService.updateFileInfo(id, data.fileInfo, { user });
|
const file = await uploadService.updateFileInfo(id, data.fileInfo, { user });
|
||||||
@ -50,7 +50,7 @@ module.exports = {
|
|||||||
throw new ApplicationError('Cannot replace a file with multiple ones');
|
throw new ApplicationError('Cannot replace a file with multiple ones');
|
||||||
}
|
}
|
||||||
|
|
||||||
user.adminUserId = strapi.service('admin::user-hash').hashAdminUser(user);
|
user.adminUserId = strapi.service('admin::user').hashAdminUser(user);
|
||||||
|
|
||||||
const data = await validateUploadBody(body);
|
const data = await validateUploadBody(body);
|
||||||
const replacedFiles = await uploadService.replace(id, { data, file: files }, { user });
|
const replacedFiles = await uploadService.replace(id, { data, file: files }, { user });
|
||||||
@ -75,7 +75,7 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
user.adminUserId = strapi.service('admin::user-hash').hashAdminUser(user);
|
user.adminUserId = strapi.service('admin::user').hashAdminUser(user);
|
||||||
|
|
||||||
const data = await validateUploadBody(body);
|
const data = await validateUploadBody(body);
|
||||||
const uploadedFiles = await uploadService.upload({ data, files }, { user });
|
const uploadedFiles = await uploadService.upload({ data, files }, { user });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user