fix: check report access with the user id of the lists site

The user id differs per site, so the id from the page context showed
"Нет доступа" in reports when the page was not on /sites/stroy.
The id and the photo folder path now come from settings.siteUrl.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Тимур Городецкий
2026-10-19 16:17:56 +05:00
parent cb810972c4
commit f0272c2170
10 changed files with 97 additions and 19 deletions
@@ -11,7 +11,8 @@ export interface IReportListDeps {
dataverse: IHttpClient;
siteUrl: string;
dataverseUrl: string;
userId: number | undefined;
/** Id пользователя на сайте со списками (не на сайте страницы) — см. IAppServices.getCurrentUserId. */
getCurrentUserId: () => Promise<number>;
}
/** Справочники для подписей карточек: компания по Id, путь объекта. */
@@ -49,7 +50,8 @@ export async function loadReportList(
projectId: number,
range: IDateRange
): Promise<ReportListInitResult> {
const accessResult = await fetchReportAccess(deps.sharePoint, deps.siteUrl, deps.userId, projectId);
const userId = await deps.getCurrentUserId();
const accessResult = await fetchReportAccess(deps.sharePoint, deps.siteUrl, userId, projectId);
if (!accessResult) return { kind: 'denied' };
const base = { kind: 'ready' as const, projectName: accessResult.projectName, access: accessResult.access };
@@ -149,7 +149,7 @@ describe('loadReportList', () => {
}
}
]);
const deps = { sharePoint, dataverse, siteUrl: SITE, dataverseUrl: DV, userId: 42 };
const deps = { sharePoint, dataverse, siteUrl: SITE, dataverseUrl: DV, getCurrentUserId: async () => 42 };
const result = await loadReportList(deps, 5, WEEK);
@@ -174,7 +174,7 @@ describe('loadReportList', () => {
it('нет доступа — denied, справочники не грузятся', async () => {
const sharePoint = createFakeHttpClient([{ match: 'Доступы', response: { body: { value: [] } } }]);
const dataverse = createFakeHttpClient([]);
const result = await loadReportList({ sharePoint, dataverse, siteUrl: SITE, dataverseUrl: DV, userId: 42 }, 5, WEEK);
const result = await loadReportList({ sharePoint, dataverse, siteUrl: SITE, dataverseUrl: DV, getCurrentUserId: async () => 42 }, 5, WEEK);
expect(result).toEqual({ kind: 'denied' });
expect(sharePoint.requests).toHaveLength(1);
});
@@ -182,7 +182,7 @@ describe('loadReportList', () => {
it('ошибка отчётов — экран с «Ошибка инициализации: …» и без карточек', async () => {
const sharePoint = createFakeHttpClient([access, companies, objects]);
const dataverse = createFakeHttpClient([{ match: 'cree9_reports', response: { status: 500, body: 'fail' } }]);
const result = await loadReportList({ sharePoint, dataverse, siteUrl: SITE, dataverseUrl: DV, userId: 42 }, 5, WEEK);
const result = await loadReportList({ sharePoint, dataverse, siteUrl: SITE, dataverseUrl: DV, getCurrentUserId: async () => 42 }, 5, WEEK);
expect(result).toMatchObject({
kind: 'ready',
reports: undefined,
@@ -26,7 +26,7 @@ export interface IReportListState {
/** Данные страницы отчётов: первая загрузка, «Применить» и удаление. */
export function useReportList(projectId: number, initialRange: IDateRange): IReportListState {
const { sharePoint, dataverse, settings, page } = useAppServices();
const { sharePoint, dataverse, settings, getCurrentUserId } = useAppServices();
const [phase, setPhase] = React.useState<ReportListPhase>('loading');
const [projectName, setProjectName] = React.useState<string>('');
const [access, setAccess] = React.useState<IReportAccess>(NO_ACCESS);
@@ -44,9 +44,9 @@ export function useReportList(projectId: number, initialRange: IDateRange): IRep
dataverse,
siteUrl: settings.siteUrl,
dataverseUrl: settings.dataverseUrl,
userId: page.userId
getCurrentUserId
}),
[sharePoint, dataverse, settings.siteUrl, settings.dataverseUrl, page.userId]
[sharePoint, dataverse, settings.siteUrl, settings.dataverseUrl, getCurrentUserId]
);
React.useEffect(() => {