-
Notifications
You must be signed in to change notification settings - Fork 236
feat: General users can't access other user pages #10650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/175627-admin-can-hide-user-pages
Are you sure you want to change the base?
Changes from all commits
113b1a0
3f7c80a
f03ce22
639b6cf
089a629
39c2a41
2cbf0c5
0bb6616
5e1be4f
0814c1c
4e0a11d
a6b6fbc
181e9a6
83aacc2
101b6c6
3b15e5c
3399a29
87d0779
d5c5438
5242e7e
0471f06
81d11a0
ffda7ab
e5f737e
7716f94
8e38216
b636aeb
9af9e27
a6a03ea
3f8c22d
a2c2a26
3a2c8cf
fbdc265
624a90e
dc1954e
2577f65
d82d837
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* eslint-disable react/no-danger */ | ||
| import React from 'react'; | ||
|
|
||
| import type AdminGeneralSecurityContainer from '~/client/services/AdminGeneralSecurityContainer'; | ||
|
|
||
| type Props = { | ||
| adminGeneralSecurityContainer: AdminGeneralSecurityContainer; | ||
| t: (key: string) => string; | ||
| }; | ||
|
|
||
| export const UserPageVisibilitySettings: React.FC<Props> = ({ adminGeneralSecurityContainer, t }) => { | ||
| return ( | ||
| <> | ||
| <h4 className="mb-3">{t('security_settings.user_page_visibility.user_page_visibility')}</h4> | ||
| <div className="row mb-4"> | ||
| <div className="col-md-10 offset-md-2"> | ||
| <div className="form-check form-switch form-check-success"> | ||
| <input | ||
| type="checkbox" | ||
| className="form-check-input" | ||
| id="is-user-pages-visible" | ||
| checked={adminGeneralSecurityContainer.state.isHidingUserPages} | ||
| onChange={() => { adminGeneralSecurityContainer.changeUserPageVisibility() }} | ||
| /> | ||
| <label className="form-label form-check-label" htmlFor="is-user-pages-visible"> | ||
| {t('security_settings.user_page_visibility.hide_user_pages')} | ||
| </label> | ||
| </div> | ||
| <p | ||
| className="form-text text-muted small mt-2" | ||
| dangerouslySetInnerHTML={{ __html: t('security_settings.user_page_visibility.desc') }} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import type { | |
| import { getIdForRef, isIPageInfoForEntity } from '@growi/core'; | ||
| import { SCOPE } from '@growi/core/dist/interfaces'; | ||
| import { ErrorV3 } from '@growi/core/dist/models'; | ||
| import { isUserPage, isUsersTopPage } from '@growi/core/dist/utils/page-path-utils'; | ||
| import type { Request, Router } from 'express'; | ||
| import express from 'express'; | ||
| import { query, oneOf } from 'express-validator'; | ||
|
|
@@ -143,13 +144,15 @@ const routerFactory = (crowi: Crowi): Router => { | |
| loginRequired, validator.pageIdOrPathRequired, apiV3FormValidator, async(req: AuthorizedRequest, res: ApiV3Response) => { | ||
| const { id, path } = req.query; | ||
|
|
||
| const hideUserPages = await configManager.getConfig('security:isHidingUserPages'); | ||
| const hideRestrictedByOwner = await configManager.getConfig('security:list-policy:hideRestrictedByOwner'); | ||
| const hideRestrictedByGroup = await configManager.getConfig('security:list-policy:hideRestrictedByGroup'); | ||
|
|
||
| try { | ||
| const pages = await pageListingService.findChildrenByParentPathOrIdAndViewer( | ||
| (id || path) as string, req.user, !hideRestrictedByOwner, !hideRestrictedByGroup, | ||
| (id || path) as string, req.user, !hideRestrictedByOwner, !hideRestrictedByGroup, hideUserPages === true, | ||
| ); | ||
|
|
||
| return res.apiv3({ children: pages }); | ||
| } | ||
| catch (err) { | ||
|
|
@@ -219,10 +222,27 @@ const routerFactory = (crowi: Crowi): Router => { | |
| const pageGrantService: IPageGrantService = crowi.pageGrantService!; | ||
|
|
||
| try { | ||
| const pages = pageIds != null | ||
| let pages = pageIds != null | ||
| ? await Page.findByIdsAndViewer(pageIds as string[], req.user, null, true) | ||
| : await Page.findByPathAndViewer(path as string, req.user, null, false, true); | ||
|
|
||
| const hideUserPages = crowi.configManager.getConfig('security:isHidingUserPages'); | ||
|
|
||
| if (hideUserPages) { | ||
| pages = pages.filter((page) => { | ||
| const targetPath = page.path; | ||
| const isTargetUserPage = isUserPage(targetPath) || isUsersTopPage(targetPath); | ||
|
|
||
| if (isTargetUserPage) return false; | ||
|
|
||
| return true; | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この filter もうちょっとシンプルに書ける |
||
| } | ||
|
|
||
| if (pages.length === 0 && path != null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return res.apiv3Err(new ErrorV3('Page is not found', 'not_found'), 404); | ||
| } | ||
|
|
||
| const foundIds = pages.map(page => page._id); | ||
|
|
||
| let shortBodiesMap; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ export interface IPageListingService { | |
| user?: IUser, | ||
| showPagesRestrictedByOwner?: boolean, | ||
| showPagesRestrictedByGroup?: boolean, | ||
| hideUserPages?: boolean, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この行は不要ではないか? |
||
| ): Promise<IPageForTreeItem[]>, | ||
| } | ||
|
|
||
|
|
@@ -50,6 +51,7 @@ class PageListingService implements IPageListingService { | |
| user?: IUser, | ||
| showPagesRestrictedByOwner = false, | ||
| showPagesRestrictedByGroup = false, | ||
| hideUserPages = false, | ||
| ): Promise<IPageForTreeItem[]> { | ||
| const Page = mongoose.model<HydratedDocument<PageDocument>, PageModel>('Page'); | ||
| let queryBuilder: PageQueryBuilder; | ||
|
|
@@ -63,6 +65,11 @@ class PageListingService implements IPageListingService { | |
| // Use $eq for user-controlled sources. see: https://codeql.github.com/codeql-query-help/javascript/js-sql-injection/#recommendation | ||
| queryBuilder = new PageQueryBuilder(Page.find({ parent: { $eq: parentId } }), true); | ||
| } | ||
|
|
||
| if (hideUserPages) { | ||
| queryBuilder.addConditionToListByNotMatchPathAndChildren('/user'); | ||
| } | ||
|
|
||
| await queryBuilder.addViewerCondition(user, null, undefined, showPagesRestrictedByOwner, showPagesRestrictedByGroup); | ||
|
|
||
| const pages: HydratedDocument<Omit<IPageForTreeItem, 'processData'>>[] = await queryBuilder | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v7.3 ベースのコードのように見える
master ブランチからの乖離が激しいので follow してから再実装してください