Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Sep 27, 2023
1 parent dd05c82 commit d2244cf
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 69 deletions.
11 changes: 8 additions & 3 deletions databox/api/src/Elasticsearch/AssetDataTemplateSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,19 @@ protected function createACLBoolQuery(array $filters, ?string $userId, array $gr
throw new BadRequestHttpException('Collection is not in the same workspace');
}

if (!$this->security->isGranted(AbstractVoter::READ, $workspace)) {
throw new AccessDeniedHttpException('Cannot read workspace');
$aclBoolQuery = new Query\BoolQuery();

if (null !== $collection) {
if (!$this->security->isGranted(AbstractVoter::EDIT, $collection)) {
$aclBoolQuery->addMust(new Query\Term(['collectionId' => 'NONE']));
}
} elseif (!$this->security->isGranted(AbstractVoter::READ, $workspace)) {
$aclBoolQuery->addMust(new Query\Term(['workspaceId' => 'NONE']));
}

$rootQuery = new Query\BoolQuery();
$rootQuery->addMust(new Query\Term(['workspaceId' => $workspace->getId()]));

$aclBoolQuery = new Query\BoolQuery();
$rootQuery->addMust($aclBoolQuery);
$shoulds = [];

Expand Down
5 changes: 0 additions & 5 deletions databox/api/src/Security/Voter/AssetVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ protected function voteOnAttribute(string $attribute, $subject, TokenInterface $
$userId = $user instanceof JwtUser ? $user->getId() : false;
$isOwner = fn (): bool => $userId && $subject->getOwnerId() === $userId;

$workspace = $subject->getWorkspace();
if (!$this->security->isGranted(AbstractVoter::READ, $workspace)) {
return false;
}

switch ($attribute) {
case self::CREATE:
if (null !== $collection = $subject->getReferenceCollection()) {
Expand Down
3 changes: 0 additions & 3 deletions databox/api/src/Security/Voter/CollectionVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ private function doVote(string $attribute, Collection $subject, TokenInterface $
$isOwner = fn (): bool => $userId && $subject->getOwnerId() === $userId;

$workspace = $subject->getWorkspace();
if (!$this->security->isGranted(AbstractVoter::READ, $workspace)) {
return false;
}

return match ($attribute) {
self::CREATE => $subject->getParent() ? $this->security->isGranted(AbstractVoter::EDIT, $subject->getParent())
Expand Down
19 changes: 6 additions & 13 deletions databox/client/src/components/Routing/router.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, {Component, FunctionComponent, useContext} from 'react';
import {Navigate, Route} from 'react-router-dom';
import {getPath, RouteDefinition} from "../../routes";
import {Route} from 'react-router-dom';
import {RouteDefinition} from "../../routes";
import {UserContext} from "../Security/UserContext";
import {useKeycloakUrls} from "../../lib/keycloak";

type WrapperProps = {
component: FunctionComponent<any>
Expand All @@ -12,16 +13,12 @@ function RouteProxy({
public: isPublic,
}: WrapperProps) {
const {user} = useContext(UserContext);
const {getLoginUrl} = useKeycloakUrls();

if (!isPublic && !user) {
const currentPath = getCurrentPath();
document.location.href = getLoginUrl();

return <Navigate
to={getPath('login')}
state={{
from: currentPath,
}}
/>
return <></>
}

return <Component/>
Expand Down Expand Up @@ -67,7 +64,3 @@ export default function createRoute(
/>}
/>
};

function getCurrentPath(): string {
return window.location.href.replace(window.location.origin, '');
}
2 changes: 1 addition & 1 deletion expose/client/config-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
keycloakUrl: env.KEYCLOAK_URL,
realmName: env.KEYCLOAK_REALM_NAME,
clientId: env.CLIENT_ID,
requestSignatureTtl: env.S3_REQUEST_SIGNATURE_TTL,
requestSignatureTtl: env.S3_REQUEST_SIGNATURE_TTL ? parseInt(env.S3_REQUEST_SIGNATURE_TTL) : 86400,
disableIndexPage: ['true', '1', 'on'].includes(env.DISABLE_INDEX_PAGE),
};
});
8 changes: 4 additions & 4 deletions expose/client/src/component/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ class App extends PureComponent {
}

render() {
const css = config.get('globalCSS');
const css = config.globalCSS;

return <Router>
{css && <style>
{css}
</style>}
{config.get('displayServicesMenu') && <DashboardMenu
dashboardBaseUrl={config.get('dashboardBaseUrl')}
{config.displayServicesMenu && <DashboardMenu
dashboardBaseUrl={config.dashboardBaseUrl}
/>}
<Switch>
<Route path="/auth" component={OAuthR}/>
{!config.get('disableIndexPage') && <Route path="/" exact component={PublicationIndex} />}
{!config.disableIndexPage && <Route path="/" exact component={PublicationIndex} />}
<Route path="/embed/:asset" exact render={({match: {params}}) => <EmbeddedAsset
id={params.asset}
/>}/>
Expand Down
3 changes: 2 additions & 1 deletion expose/client/src/component/ConfigWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default function ConfigWrapper() {
.get(`/config`)
.then((res) => {
Object.keys(res).forEach(k => {
config.set(k, res[k]);
// @ts-ignore bypass readonly
config[k] = res[k];
});

setLoaded(true);
Expand Down
4 changes: 2 additions & 2 deletions expose/client/src/component/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Layout extends PureComponent {
super(props);

this.state = {
displayMenu: config.get('sidebarDefaultOpen'),
displayMenu: config.sidebarDefaultOpen,
}
}

Expand All @@ -42,7 +42,7 @@ class Layout extends PureComponent {
{this.renderAuthenticated()}
<div className="p-3">
<h1>
{!config.get('disableIndexPage') ? <Link to={'/'} className="logo">
{!config.disableIndexPage ? <Link to={'/'} className="logo">
<Logo/>
</Link> : <Logo/>}
</h1>
Expand Down
6 changes: 3 additions & 3 deletions expose/client/src/component/Logo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'react';
import config from '../lib/config';

export function Logo() {
const title = config.get('clientLogoAlt') || 'Expose.';
const title = config.clientLogoAlt || 'Expose.';

if (config.get('clientLogoUrl')) {
if (config.clientLogoUrl) {
return <div className="exp-logo">
<img
src={config.get('clientLogoUrl')}
src={config.clientLogoUrl}
alt={title}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion expose/client/src/component/Publication.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Publication extends PureComponent {

this.timeout && clearTimeout(this.timeout);

const ttl = config.get('requestSignatureTtl');
const ttl = config.requestSignatureTtl;

if (!ttl) {
throw new Error(`Missing requestSignatureTtl`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class GalleryLayout extends React.Component {
};

render() {
const {assetId, data, options} = this.props;
const {data, options} = this.props;
const {currentIndex} = this.state;
const {
assets,
Expand Down
2 changes: 1 addition & 1 deletion expose/client/src/component/layouts/mapbox/MapboxLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {logAssetView} from "../../../lib/log";
import {getThumbPlaceholder} from "../shared-components/placeholders";

export function initMapbox(mapContainer, {lng, lat, zoom}) {
mapboxgl.accessToken = config.get('mapBoxToken');
mapboxgl.accessToken = config.mapBoxToken;

let map = new mapboxgl.Map({
container: mapContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class PublicationHeader extends PureComponent {
</div>}
<h1>{title}</h1>
{date ? <time>{moment(date).format('LLLL')}</time> : ''}
{assets.length > 0 && config.get('zippyEnabled') && <div style={{
{assets.length > 0 && config.zippyEnabled && <div style={{
position: 'absolute',
top: 0,
right: 0,
Expand All @@ -33,7 +33,7 @@ export default class PublicationHeader extends PureComponent {
{description && <Description
descriptionHtml={description}
/>}
{data.downloadEnabled && config.get('zippyEnabled') && assets.length > 0 && <div className={'download-archive'}>
{data.downloadEnabled && config.zippyEnabled && assets.length > 0 && <div className={'download-archive'}>
<ZippyDownloadButton id={data.id} data={data} />
</div>}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {oauthClient} from "../../lib/api-client";
type Props = {};

function createLoginUrl(): string {
const autoConnectIdP = config.get('autoConnectIdP');
const autoConnectIdP = config.autoConnectIdP;

setAuthRedirect(document.location.pathname);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {Publication} from "../../types";
import {securityMethods} from "./methods";
import FullPageLoader from "../FullPageLoader";
import {logPublicationView} from "../../lib/log";
import config from "../../lib/config";
import {oauthClient} from "../../lib/api-client";

type Props = PropsWithChildren<{
Expand Down
2 changes: 1 addition & 1 deletion expose/client/src/component/themes/ThemeEditorProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ThemeEditorProxy extends Component {
};

state = {
hidden: !config.get('devMode'),
hidden: !config.devMode,
};

static getDerivedStateFromProps(props, state) {
Expand Down
39 changes: 13 additions & 26 deletions expose/client/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@

declare global {
interface Window {
config: Record<string, any>;
config: {
locales: string[];
autoConnectIdP: string | undefined | null;
baseUrl: string;
keycloakUrl: string;
realmName: string;
clientId: string;
requestSignatureTtl: string;
disableIndexPage: string;
dashboardBaseUrl: string;
globalCSS: string | undefined;
};
}
}

const configData = window.config;

class Config {
get(key: string): any {
return configData[key];
}

set(key: string, value: any): void {
configData[key] = value;
}

getApiBaseUrl(): string {
return configData.baseUrl;
}

getAuthBaseUrl(): string {
return configData.authBaseUrl;
}

getClientId(): string {
return this.get('clientId');
}
}

const config = new Config();
const config = window.config;

export default config;

0 comments on commit d2244cf

Please sign in to comment.