mirror of
https://github.com/strapi/strapi.git
synced 2025-10-27 16:10:08 +00:00
Update admin::administrator queries to match its new name
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
This commit is contained in:
parent
1f3506710d
commit
364de7d2e8
@ -173,11 +173,9 @@ module.exports = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const adminsWithSameEmail = await strapi.query('administrator', 'admin').findOne({ email });
|
const adminsWithSameEmail = await strapi.query('user', 'admin').findOne({ email });
|
||||||
|
|
||||||
const adminsWithSameUsername = await strapi
|
const adminsWithSameUsername = await strapi.query('user', 'admin').findOne({ username });
|
||||||
.query('administrator', 'admin')
|
|
||||||
.findOne({ username });
|
|
||||||
|
|
||||||
if (adminsWithSameEmail) {
|
if (adminsWithSameEmail) {
|
||||||
return ctx.badRequest(
|
return ctx.badRequest(
|
||||||
@ -208,7 +206,7 @@ module.exports = {
|
|||||||
password: await strapi.admin.services.auth.hashPassword(password),
|
password: await strapi.admin.services.auth.hashPassword(password),
|
||||||
};
|
};
|
||||||
|
|
||||||
const data = await strapi.query('administrator', 'admin').create(user);
|
const data = await strapi.query('user', 'admin').create(user);
|
||||||
|
|
||||||
// Send 201 `created`
|
// Send 201 `created`
|
||||||
ctx.created(strapi.admin.services.auth.sanitizeUser(data));
|
ctx.created(strapi.admin.services.auth.sanitizeUser(data));
|
||||||
@ -246,14 +244,14 @@ module.exports = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const admin = await strapi.query('administrator', 'admin').findOne({ id });
|
const admin = await strapi.query('user', 'admin').findOne({ id });
|
||||||
|
|
||||||
// check the user exists
|
// check the user exists
|
||||||
if (!admin) return ctx.notFound('Administrator not found');
|
if (!admin) return ctx.notFound('Administrator not found');
|
||||||
|
|
||||||
// check there are not user with requested email
|
// check there are not user with requested email
|
||||||
if (email !== admin.email) {
|
if (email !== admin.email) {
|
||||||
const adminsWithSameEmail = await strapi.query('administrator', 'admin').findOne({ email });
|
const adminsWithSameEmail = await strapi.query('user', 'admin').findOne({ email });
|
||||||
|
|
||||||
if (adminsWithSameEmail && adminsWithSameEmail.id !== admin.id) {
|
if (adminsWithSameEmail && adminsWithSameEmail.id !== admin.id) {
|
||||||
return ctx.badRequest(
|
return ctx.badRequest(
|
||||||
@ -269,9 +267,7 @@ module.exports = {
|
|||||||
|
|
||||||
// check there are not user with requested username
|
// check there are not user with requested username
|
||||||
if (username !== admin.username) {
|
if (username !== admin.username) {
|
||||||
const adminsWithSameUsername = await strapi
|
const adminsWithSameUsername = await strapi.query('user', 'admin').findOne({ username });
|
||||||
.query('administrator', 'admin')
|
|
||||||
.findOne({ username });
|
|
||||||
|
|
||||||
if (adminsWithSameUsername && adminsWithSameUsername.id !== admin.id) {
|
if (adminsWithSameUsername && adminsWithSameUsername.id !== admin.id) {
|
||||||
return ctx.badRequest(
|
return ctx.badRequest(
|
||||||
@ -295,7 +291,7 @@ module.exports = {
|
|||||||
user.password = await strapi.admin.services.auth.hashPassword(password);
|
user.password = await strapi.admin.services.auth.hashPassword(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await strapi.query('administrator', 'admin').update({ id }, user);
|
const data = await strapi.query('user', 'admin').update({ id }, user);
|
||||||
|
|
||||||
// Send 200 `ok`
|
// Send 200 `ok`
|
||||||
ctx.send(data);
|
ctx.send(data);
|
||||||
|
|||||||
@ -54,7 +54,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the admin exists.
|
// Check if the admin exists.
|
||||||
const admin = await strapi.query('administrator', 'admin').findOne(query);
|
const admin = await strapi.query('user', 'admin').findOne(query);
|
||||||
|
|
||||||
if (!admin) {
|
if (!admin) {
|
||||||
return ctx.badRequest(
|
return ctx.badRequest(
|
||||||
@ -145,7 +145,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// First, check if their is at least one admin
|
// First, check if their is at least one admin
|
||||||
const admins = await strapi.query('administrator', 'admin').find({ _limit: 1 });
|
const admins = await strapi.query('user', 'admin').find({ _limit: 1 });
|
||||||
|
|
||||||
if (admins.length > 0) {
|
if (admins.length > 0) {
|
||||||
return ctx.badRequest(
|
return ctx.badRequest(
|
||||||
@ -159,7 +159,7 @@ module.exports = {
|
|||||||
|
|
||||||
params.password = await strapi.admin.services.auth.hashPassword(params.password);
|
params.password = await strapi.admin.services.auth.hashPassword(params.password);
|
||||||
|
|
||||||
const admin = await strapi.query('administrator', 'admin').findOne({
|
const admin = await strapi.query('user', 'admin').findOne({
|
||||||
email: params.email,
|
email: params.email,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const admin = await strapi.query('administrator', 'admin').create(params);
|
const admin = await strapi.query('user', 'admin').create(params);
|
||||||
|
|
||||||
admin.isAdmin = true;
|
admin.isAdmin = true;
|
||||||
|
|
||||||
@ -244,9 +244,7 @@ module.exports = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const admin = await strapi
|
const admin = await strapi.query('user', 'admin').findOne({ resetPasswordToken: `${code}` });
|
||||||
.query('administrator', 'admin')
|
|
||||||
.findOne({ resetPasswordToken: `${code}` });
|
|
||||||
|
|
||||||
if (!admin) {
|
if (!admin) {
|
||||||
return ctx.badRequest(
|
return ctx.badRequest(
|
||||||
@ -263,9 +261,7 @@ module.exports = {
|
|||||||
password: await strapi.admin.services.auth.hashPassword(password),
|
password: await strapi.admin.services.auth.hashPassword(password),
|
||||||
};
|
};
|
||||||
|
|
||||||
const updatedAdmin = await strapi
|
const updatedAdmin = await strapi.query('user', 'admin').update({ id: admin.id }, data);
|
||||||
.query('administrator', 'admin')
|
|
||||||
.update({ id: admin.id }, data);
|
|
||||||
|
|
||||||
return ctx.send({
|
return ctx.send({
|
||||||
jwt: strapi.admin.services.auth.createJwtToken(updatedAdmin),
|
jwt: strapi.admin.services.auth.createJwtToken(updatedAdmin),
|
||||||
@ -296,7 +292,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the admin thanks to his email.
|
// Find the admin thanks to his email.
|
||||||
const admin = await strapi.query('administrator', 'admin').findOne({ email });
|
const admin = await strapi.query('user', 'admin').findOne({ email });
|
||||||
|
|
||||||
// admin not found.
|
// admin not found.
|
||||||
if (!admin) {
|
if (!admin) {
|
||||||
@ -339,7 +335,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the admin.
|
// Update the admin.
|
||||||
await strapi.query('administrator', 'admin').update({ id: admin.id }, { resetPasswordToken });
|
await strapi.query('user', 'admin').update({ id: admin.id }, { resetPasswordToken });
|
||||||
|
|
||||||
ctx.send({ ok: true });
|
ctx.send({ ok: true });
|
||||||
},
|
},
|
||||||
|
|||||||
@ -14,7 +14,7 @@ module.exports = async (ctx, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isAdmin) {
|
if (isAdmin) {
|
||||||
ctx.state.admin = await strapi.query('administrator', 'admin').findOne({ id }, []);
|
ctx.state.admin = await strapi.query('user', 'admin').findOne({ id }, []);
|
||||||
} else {
|
} else {
|
||||||
ctx.state.user = await strapi.plugins['users-permissions'].services.user.fetch({ id });
|
ctx.state.user = await strapi.plugins['users-permissions'].services.user.fetch({ id });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -144,7 +144,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async init(ctx) {
|
async init(ctx) {
|
||||||
const admins = await strapi.query('administrator', 'admin').find({ _limit: 1 });
|
const admins = await strapi.query('user', 'admin').find({ _limit: 1 });
|
||||||
|
|
||||||
ctx.send({ hasAdmin: admins.length > 0 });
|
ctx.send({ hasAdmin: admins.length > 0 });
|
||||||
},
|
},
|
||||||
|
|||||||
@ -14,9 +14,7 @@ module.exports = {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const numberOfAdministrators = await strapi
|
const numberOfAdministrators = await strapi.query('user', 'admin').find({ _limit: 1 });
|
||||||
.query('administrator', 'admin')
|
|
||||||
.find({ _limit: 1 });
|
|
||||||
|
|
||||||
return numberOfAdministrators.length > 0;
|
return numberOfAdministrators.length > 0;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user