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:
@@ -1,4 +1,5 @@
|
||||
import { IAppServices } from '../../services/AppServices';
|
||||
import { siteServerRelativeUrl } from '../../services/siteUser';
|
||||
import { createSharePointReportRepository, ISharePointReportRepository } from './sharePointReportRepository';
|
||||
import { createDataverseReportRepository, IDataverseReportRepository } from './dataverseReportRepository';
|
||||
|
||||
@@ -9,13 +10,15 @@ export interface IReportServices {
|
||||
siteUrl: string;
|
||||
}
|
||||
|
||||
// Всё — от сайта со списками (settings.siteUrl), а не от сайта страницы: в workbench корневого
|
||||
// сайта id пользователя и путь к библиотеке DocLib там другие.
|
||||
export function createReportServices(services: IAppServices): IReportServices {
|
||||
return {
|
||||
sp: createSharePointReportRepository({
|
||||
client: services.sharePoint,
|
||||
siteUrl: services.settings.siteUrl,
|
||||
userId: services.page.userId,
|
||||
webServerRelativeUrl: services.page.webServerRelativeUrl
|
||||
getCurrentUserId: services.getCurrentUserId,
|
||||
webServerRelativeUrl: siteServerRelativeUrl(services.settings.siteUrl)
|
||||
}),
|
||||
dv: createDataverseReportRepository(services.dataverse, services.settings.dataverseUrl),
|
||||
siteUrl: services.settings.siteUrl
|
||||
|
||||
@@ -17,7 +17,7 @@ const repositoryWith = (routes: IFakeRoute[]): {
|
||||
const repository = createSharePointReportRepository({
|
||||
client,
|
||||
siteUrl: SITE,
|
||||
userId: 42,
|
||||
getCurrentUserId: async () => 42,
|
||||
webServerRelativeUrl: '/sites/stroy/'
|
||||
});
|
||||
return { client, repository };
|
||||
|
||||
@@ -111,9 +111,13 @@ export function fileAddUrl(siteUrl: string, serverRelativeFolderUrl: string, fil
|
||||
export interface ISharePointReportDeps {
|
||||
client: IHttpClient;
|
||||
siteUrl: string;
|
||||
/** Id текущего пользователя (legacyPageContext.userId) — по нему ищется строка «Доступы». */
|
||||
userId: number | undefined;
|
||||
/** Серверный относительный URL сайта — для пути к папке фото. */
|
||||
/**
|
||||
* Id текущего пользователя на сайте со списками — по нему ищется строка «Доступы».
|
||||
* Старый код брал legacyPageContext.userId (id на сайте страницы); в workbench корневого сайта
|
||||
* это другой id, и доступ не находился. Теперь — `_api/web/currentuser` сайта со списками.
|
||||
*/
|
||||
getCurrentUserId: () => Promise<number>;
|
||||
/** Серверный относительный URL сайта со списками (`/sites/stroy`) — для пути к папке фото. */
|
||||
webServerRelativeUrl: string;
|
||||
}
|
||||
|
||||
@@ -224,8 +228,11 @@ export function createSharePointReportRepository(deps: ISharePointReportDeps): I
|
||||
createListItem,
|
||||
|
||||
checkAccess: async (projectId) => {
|
||||
const rows = await getItems<IAccessRaw>(LISTS.access, { filter: `projectId eq ${projectId}` });
|
||||
return pickAccess(rows, deps.userId);
|
||||
const [rows, userId] = await Promise.all([
|
||||
getItems<IAccessRaw>(LISTS.access, { filter: `projectId eq ${projectId}` }),
|
||||
deps.getCurrentUserId()
|
||||
]);
|
||||
return pickAccess(rows, userId);
|
||||
},
|
||||
|
||||
uploadPhotos: async (projectId, reportNumber, photos) => {
|
||||
|
||||
Reference in New Issue
Block a user