fix: reset password regression (#1574)
This commit is contained in:
@@ -138,7 +138,7 @@ const DefaultAccount: React.FC<Props> = (props) => {
|
||||
data={data}
|
||||
/>
|
||||
{hasSavePermission && (
|
||||
<FormSubmit>{t('general:save')}</FormSubmit>
|
||||
<FormSubmit buttonId="action-save">{t('general:save')}</FormSubmit>
|
||||
)}
|
||||
</div>
|
||||
<div className={`${baseClass}__sidebar-fields`}>
|
||||
|
||||
@@ -101,6 +101,7 @@ const Auth: React.FC<Props> = (props) => {
|
||||
)}
|
||||
{(!changingPassword && !requirePassword) && (
|
||||
<Button
|
||||
id="change-password"
|
||||
size="small"
|
||||
buttonStyle="secondary"
|
||||
onClick={() => handleChangePassword(true)}
|
||||
|
||||
@@ -72,13 +72,15 @@ async function update(incomingArgs: Arguments): Promise<Document> {
|
||||
autosave = false,
|
||||
} = args;
|
||||
|
||||
let { data } = args;
|
||||
|
||||
if (!id) {
|
||||
throw new APIError('Missing ID of document to update.', httpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
let { data } = args;
|
||||
const { password } = data;
|
||||
const shouldSaveDraft = Boolean(draftArg && collectionConfig.versions.drafts);
|
||||
const shouldSavePassword = Boolean(password && collectionConfig.auth && !shouldSaveDraft);
|
||||
const lean = !shouldSavePassword;
|
||||
|
||||
// /////////////////////////////////////
|
||||
// Access
|
||||
@@ -109,12 +111,13 @@ async function update(incomingArgs: Arguments): Promise<Document> {
|
||||
|
||||
const query = await Model.buildQuery(queryToBuild, locale);
|
||||
|
||||
const doc = await getLatestCollectionVersion({ payload, collection, id, query });
|
||||
const doc = await getLatestCollectionVersion({ payload, collection, id, query, lean });
|
||||
|
||||
if (!doc && !hasWherePolicy) throw new NotFound(t);
|
||||
if (!doc && hasWherePolicy) throw new Forbidden(t);
|
||||
|
||||
const docWithLocales: Document = JSON.parse(JSON.stringify(doc));
|
||||
let docWithLocales: Document = JSON.stringify(lean ? doc : doc.toJSON({ virtuals: true }));
|
||||
docWithLocales = JSON.parse(docWithLocales);
|
||||
|
||||
const originalDoc = await afterRead({
|
||||
depth: 0,
|
||||
@@ -211,9 +214,7 @@ async function update(incomingArgs: Arguments): Promise<Document> {
|
||||
// Handle potential password update
|
||||
// /////////////////////////////////////
|
||||
|
||||
const { password } = data;
|
||||
|
||||
if (password && collectionConfig.auth && !shouldSaveDraft) {
|
||||
if (shouldSavePassword) {
|
||||
await doc.setPassword(password as string);
|
||||
await doc.save();
|
||||
delete data.password;
|
||||
|
||||
@@ -7,6 +7,7 @@ type Args = {
|
||||
collection: Collection,
|
||||
query: Record<string, unknown>
|
||||
id: string | number
|
||||
lean?: boolean
|
||||
}
|
||||
|
||||
export const getLatestCollectionVersion = async <T extends TypeWithID = any>({
|
||||
@@ -17,6 +18,7 @@ export const getLatestCollectionVersion = async <T extends TypeWithID = any>({
|
||||
},
|
||||
query,
|
||||
id,
|
||||
lean = true,
|
||||
}: Args): Promise<T> => {
|
||||
let version;
|
||||
if (config.versions?.drafts) {
|
||||
@@ -24,10 +26,10 @@ export const getLatestCollectionVersion = async <T extends TypeWithID = any>({
|
||||
parent: id,
|
||||
}, {}, {
|
||||
sort: { updatedAt: 'desc' },
|
||||
lean: true,
|
||||
lean,
|
||||
});
|
||||
}
|
||||
const collection = await Model.findOne(query).lean() as Document;
|
||||
const collection = await Model.findOne(query, {}, { lean }) as Document;
|
||||
version = await version;
|
||||
if (!version || version.updatedAt < collection.updatedAt) {
|
||||
return collection;
|
||||
|
||||
Reference in New Issue
Block a user