mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +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: {
|
||||
findOne,
|
||||
},
|
||||
'user-hash': {
|
||||
user: {
|
||||
hashAdminUser,
|
||||
},
|
||||
},
|
||||
@ -155,7 +155,7 @@ describe('Role controller', () => {
|
||||
actionProvider: { get: jest.fn() },
|
||||
conditionProvider: { values: jest.fn(() => []) },
|
||||
},
|
||||
'user-hash': {
|
||||
user: {
|
||||
hashAdminUser,
|
||||
},
|
||||
},
|
||||
@ -226,7 +226,7 @@ describe('Role controller', () => {
|
||||
})),
|
||||
},
|
||||
},
|
||||
'user-hash': {
|
||||
user: {
|
||||
hashAdminUser,
|
||||
},
|
||||
},
|
||||
|
@ -28,8 +28,6 @@ describe('User Controller', () => {
|
||||
services: {
|
||||
user: {
|
||||
exists,
|
||||
},
|
||||
'user-hash': {
|
||||
hashAdminUser,
|
||||
},
|
||||
},
|
||||
@ -68,8 +66,6 @@ describe('User Controller', () => {
|
||||
exists,
|
||||
create,
|
||||
sanitizeUser,
|
||||
},
|
||||
'user-hash': {
|
||||
hashAdminUser,
|
||||
},
|
||||
},
|
||||
|
@ -122,7 +122,7 @@ module.exports = {
|
||||
roles: superAdminRole ? [superAdminRole.id] : [],
|
||||
});
|
||||
|
||||
const adminUserId = await getService('user-hash').hashAdminUser(user);
|
||||
const adminUserId = await getService('user').hashAdminUser(user);
|
||||
|
||||
strapi.telemetry.send(adminUserId, 'didCreateFirstAdmin');
|
||||
|
||||
|
@ -98,7 +98,7 @@ module.exports = {
|
||||
async updatePermissions(ctx) {
|
||||
const { id } = ctx.params;
|
||||
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 { sanitizePermission, actionProvider } = getService('permission');
|
||||
|
@ -13,7 +13,7 @@ const { getService } = require('../utils');
|
||||
module.exports = {
|
||||
async create(ctx) {
|
||||
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);
|
||||
|
||||
|
@ -14,5 +14,4 @@ module.exports = {
|
||||
action: require('./action'),
|
||||
'api-token': require('./api-token'),
|
||||
'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 { defaults } = require('lodash/fp');
|
||||
const crypto = require('crypto');
|
||||
const { stringIncludes } = require('@strapi/utils');
|
||||
const { ValidationError } = require('@strapi/utils').errors;
|
||||
const { createUser, hasSuperAdminRole } = require('../domain/user');
|
||||
@ -323,6 +324,14 @@ const getLanguagesInUse = async () => {
|
||||
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 = {
|
||||
create,
|
||||
updateById,
|
||||
@ -341,4 +350,5 @@ module.exports = {
|
||||
displayWarningIfUsersDontHaveRole,
|
||||
resetPasswordByEmail,
|
||||
getLanguagesInUse,
|
||||
hashAdminUser,
|
||||
};
|
||||
|
@ -112,7 +112,7 @@ describe('Single Types', () => {
|
||||
permission: {
|
||||
createPermissionsManager,
|
||||
},
|
||||
'user-hash': {
|
||||
user: {
|
||||
hashAdminUser,
|
||||
},
|
||||
},
|
||||
|
@ -65,7 +65,7 @@ module.exports = {
|
||||
const { userAbility, user } = ctx.state;
|
||||
const { model } = ctx.params;
|
||||
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();
|
||||
|
||||
|
@ -75,7 +75,7 @@ module.exports = {
|
||||
const { userAbility } = ctx.state;
|
||||
const { uid } = ctx.params;
|
||||
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 metricsService = getService('metrics');
|
||||
|
@ -46,7 +46,7 @@ module.exports = {
|
||||
const { user, userAbility } = ctx.state;
|
||||
const { model } = ctx.params;
|
||||
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 permissionChecker = getService('permission-checker').create({ userAbility, model });
|
||||
|
@ -47,7 +47,7 @@ module.exports = {
|
||||
|
||||
async createContentType(ctx) {
|
||||
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 {
|
||||
await validateContentTypeInput(body);
|
||||
|
@ -16,7 +16,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -23,7 +23,7 @@ module.exports = {
|
||||
id
|
||||
);
|
||||
|
||||
user.adminUserId = strapi.service('admin::user-hash').hashAdminUser(user);
|
||||
user.adminUserId = strapi.service('admin::user').hashAdminUser(user);
|
||||
|
||||
const data = await validateUploadBody(body);
|
||||
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');
|
||||
}
|
||||
|
||||
user.adminUserId = strapi.service('admin::user-hash').hashAdminUser(user);
|
||||
user.adminUserId = strapi.service('admin::user').hashAdminUser(user);
|
||||
|
||||
const data = await validateUploadBody(body);
|
||||
const replacedFiles = await uploadService.replace(id, { data, file: files }, { user });
|
||||
@ -75,7 +75,7 @@ module.exports = {
|
||||
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 uploadedFiles = await uploadService.upload({ data, files }, { user });
|
||||
|
Loading…
x
Reference in New Issue
Block a user