Skip to content

Commit 97aeece

Browse files
Merge branch 'react' into demo
2 parents 12356fc + 3474149 commit 97aeece

11 files changed

Lines changed: 47 additions & 22 deletions

File tree

fixture/adminizerConfig.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ const config: AdminpanelConfig = {
368368
// defaultUserGroup: "test",
369369
// confirmationRequired: false
370370
// },
371+
auth: {
372+
enable: true,
373+
description: "Login `demo`, password `demo`"
374+
},
371375
dashboard: false,
372376
forms: {
373377
data: {
@@ -511,10 +515,6 @@ const config: AdminpanelConfig = {
511515
//config: string | object // db-migrate config
512516
},
513517
showVersion: true,
514-
auth: {
515-
enable: true,
516-
description: "Login `demo`, password `demo`"
517-
},
518518
};
519519

520520
export default config

fixture/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async function ormSharedFixtureLift(adminizer: Adminizer) {
180180
})
181181

182182
try {
183-
adminpanelConfig.auth.enable = !!process.env.SEED_DATA
183+
// adminpanelConfig.auth.enable = !!process.env.SEED_DATA
184184
await adminizer.init(adminpanelConfig as unknown as AdminpanelConfig)
185185

186186
} catch (e) {

src/assets/js/components/add-user-form.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
TooltipTrigger,
2323
} from "@/components/ui/tooltip"
2424
import InputError from "@/components/input-error.tsx";
25+
import MaterialIcon from "@/components/material-icon.tsx";
2526

2627
type value = string | boolean | Date | Record<string, string>[]
2728

@@ -47,6 +48,10 @@ interface AddUserProps extends SharedData {
4748
postLink: string,
4849
head: string,
4950
groupHead: string,
51+
userPretend: {
52+
label: string,
53+
postLink: string,
54+
}
5055
fields: Field[]
5156
groups: Field[]
5257
locales: Record<string, string>[]
@@ -56,8 +61,7 @@ export default function AddUserForm() {
5661
const page = usePage<AddUserProps>()
5762
const [timezones, setTimezones] = useState<Record<string, string>[]>()
5863

59-
const {fields, groups} = page.props;
60-
64+
const {fields, groups, auth} = page.props;
6165
const {
6266
data,
6367
setData,
@@ -243,6 +247,14 @@ export default function AddUserForm() {
243247
)}
244248
</div>
245249
</div>
250+
{auth.user.isAdministrator && (
251+
<Button className="w-fit" asChild variant="outline">
252+
<Link href={page.props.userPretend.postLink} method="post" data={{ login: data.login, pretend: true }}>
253+
<MaterialIcon name="masks" className="!text-[18px]"/>
254+
{page.props.userPretend.label}
255+
</Link>
256+
</Button>
257+
)}
246258
<div className="flex gap-3">
247259
<label className="font-bold text-xl">{getField('userPassword')?.label}</label>
248260
<TooltipProvider>

src/assets/js/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface User {
4646
login: string;
4747
email: string;
4848
avatar?: string;
49+
isAdministrator: boolean;
4950
[key: string]: unknown;
5051
}
5152

src/controllers/edit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export default async function edit(req: ReqType, res: ResType) {
168168
let fieldConfigConfig = fields[field].config as BaseFieldConfig;
169169
if (fieldConfigConfig.type === 'mediamanager') {
170170
if (fields[field].model.type === 'association-many') {
171-
console.log(fieldConfigConfig.options);
171+
// console.log(fieldConfigConfig.options);
172172
record[field] = await getRelationsMediaManager({
173173
list: record[field],
174174
mediaManagerId: (fieldConfigConfig.options as MediaManagerOptionsField).id ?? "default"

src/controllers/login.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,34 @@ export default async function login(req: ReqType, res: ResType) {
1414
let password = req.body.password;
1515
let captchaSolution = req.body.captchaSolution;
1616

17-
// Verify CAPTCHA solution
18-
const isCaptchaValid = powCaptcha.check(captchaSolution, `login:${req.ip}`);
19-
if (!isCaptchaValid) {
20-
return inertiaAdminMessage(req, "Invalid CAPTCHA solution", 'captchaSolution');
21-
}
22-
2317
let user: ModelsAP["UserAP"];
2418
try {
2519
// TODO refactor CRUD functions for DataAccessor usage
2620
user = await req.adminizer.modelHandler.model.get("UserAP")["_findOne"]({login: login});
2721
} catch (e) {
2822
return res.status(500).send({error: e.message || 'Internal Server Error'});
2923
}
24+
3025
if (req.body.pretend) {
3126
if (!user) {
3227
return res.sendStatus(404);
3328
}
3429
if (req.session.UserAP.isAdministrator) {
3530
req.session.adminPretender = req.session.UserAP;
3631
req.session.UserAP = user;
37-
return res.sendStatus(200);
32+
// return res.sendStatus(200);
33+
return req.Inertia.redirect(`${req.adminizer.config.routePrefix}`);
3834
}
35+
return req.Inertia.redirect(`${req.adminizer.config.routePrefix}/`);
3936
}
4037

38+
// Verify CAPTCHA solution
39+
const isCaptchaValid = powCaptcha.check(captchaSolution, `login:${req.ip}`);
40+
if (!isCaptchaValid) {
41+
return inertiaAdminMessage(req, "Invalid CAPTCHA solution", 'captchaSolution');
42+
}
43+
44+
4145
if (!user) {
4246
return inertiaAdminMessage(req, "Wrong username", 'login');
4347
} else {

src/controllers/register.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default async function register(req: ReqType, res: ResType) {
5656
});
5757
// TODO refactor CRUD functions for DataAccessor usage
5858
let defaultUserGroup: ModelsAP["GroupAP"] = await req.adminizer.modelHandler.model.get("GroupAP")["_findOne"]({name: req.adminizer.config.registration.defaultUserGroup});
59-
console.log(userap)
59+
// console.log(userap)
6060
// TODO refactor CRUD functions for DataAccessor usage
6161
await req.adminizer.modelHandler.model.get("UserAP")["_updateOne"]({id: userap.id}, {
6262
groups: [defaultUserGroup.id]

src/helpers/inertiaUserHelper.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Entity, PropsField} from "../interfaces/types";
22

3-
interface listProps extends Record<string | number | symbol, unknown>{
3+
interface listProps extends Record<string | number | symbol, unknown> {
44
edit: boolean;
55
view: boolean;
66
btnBack: {
@@ -17,6 +17,10 @@ interface listProps extends Record<string | number | symbol, unknown>{
1717
fields: PropsField[]
1818
groups: PropsField[]
1919
locales: Record<string, string>[],
20+
userPretend: {
21+
label: string,
22+
postLink: string,
23+
}
2024
}
2125

2226
export function inertiaUserHelper(entity: Entity, req: ReqType, groups: ModelsAP["GroupAP"][], user?: ModelsAP["UserAP"], view: boolean = false) {
@@ -27,6 +31,10 @@ export function inertiaUserHelper(entity: Entity, req: ReqType, groups: ModelsAP
2731
title: req.i18n.__('Back'),
2832
link: entity.uri
2933
},
34+
userPretend: {
35+
label: req.i18n.__('Pretend to be a user'),
36+
postLink: `${req.adminizer.config.routePrefix}/model/userap/login`
37+
},
3038
passwordError: req.i18n.__('Values in "password" and "repeatPassword" fields should be the same'),
3139
btnSave: {
3240
title: req.i18n.__('Save')

src/lib/datatable/NodeTable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class NodeTable {
193193
const totalRecords = await this.model.count({});
194194
const filteredRecords = await this.model.count(queryOptions.where);
195195
const data = await this.model.find(queryOptions, dataAccessor);
196-
console.log(data, "data")
196+
// console.log(data, "data")
197197
const output = {
198198
draw: this.request.draw !== "" ? this.request.draw : 0,
199199
recordsTotal: totalRecords,
@@ -254,7 +254,7 @@ export class NodeTable {
254254
});
255255
out.push(row);
256256
});
257-
console.log(out)
257+
// console.log(out)
258258
return out;
259259
}
260260
}

src/lib/v4/model/AbstractModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ export abstract class AbstractModel<T> {
6565
public async findOne(criteria: Partial<T>, dataAccessor: DataAccessor): Promise<Partial<T> | null> {
6666
criteria = await dataAccessor.sanitizeUserRelationAccess(criteria);
6767
let record = await this._findOne(criteria);
68-
console.log(record, "record")
68+
// console.log(record, "record")
6969
return record ? dataAccessor.process(record) : null;
7070
}
7171

7272
public async find(criteria: Partial<T>, dataAccessor: DataAccessor): Promise<Partial<T>[]> {
7373
criteria = await dataAccessor.sanitizeUserRelationAccess(criteria);
7474
let records = await this._find(criteria);
75-
console.log(records, "records")
75+
// console.log(records, "records")
7676

7777
return records.map(record => dataAccessor.process(record));
7878
}

0 commit comments

Comments
 (0)