Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Oct 2, 2023
1 parent 2a3cc0e commit 0ca6deb
Show file tree
Hide file tree
Showing 33 changed files with 165 additions and 44 deletions.
9 changes: 5 additions & 4 deletions databox/api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions databox/api/src/Api/Model/Output/AssetOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class AssetOutput extends AbstractUuidOutput
#[Groups([Asset::GROUP_LIST, Asset::GROUP_READ])]
private array $tags;

#[Groups([Asset::GROUP_READ])]
public ?UserOutput $owner = null;

#[Groups([Asset::GROUP_LIST, Asset::GROUP_READ])]
private array $collections;

Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Api/Model/Output/CollectionOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class CollectionOutput extends AbstractUuidOutput
#[Groups([Collection::GROUP_LIST, Collection::GROUP_READ, Workspace::GROUP_LIST, Workspace::GROUP_READ])]
private ?string $ownerId = null;

#[Groups([Collection::GROUP_READ])]
public ?UserOutput $owner = null;

#[Groups([Collection::GROUP_LIST, Collection::GROUP_READ, Workspace::GROUP_LIST, Workspace::GROUP_READ])]
private int $privacy;

Expand Down
16 changes: 16 additions & 0 deletions databox/api/src/Api/Model/Output/UserOutput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Api\Model\Output;

use Symfony\Component\Serializer\Annotation\Groups;

final class UserOutput
{
#[Groups(['_'])]
public ?string $id = null;

#[Groups(['_'])]
public ?string $username = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class AssetOutputTransformer implements OutputTransformerInterface
{
use SecurityAwareTrait;
use UserOutputTransformerTrait;
use GroupsHelperTrait;

private ?string $lastGroupKey = null;
Expand Down Expand Up @@ -82,6 +83,12 @@ public function transform(object $data, string $outputClass, array &$context = [

$highlights = $data->getElasticHighlights();

if ($this->hasGroup([
Asset::GROUP_READ,
], $context)) {
$output->owner = $this->transformUser($data->getOwnerId());
}

if ($this->hasGroup([
Asset::GROUP_LIST,
Asset::GROUP_READ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class CollectionOutputTransformer implements OutputTransformerInterface
{
use GroupsHelperTrait;
use UserOutputTransformerTrait;
use SecurityAwareTrait;

public function __construct(
Expand All @@ -39,6 +40,12 @@ public function transform($data, string $outputClass, array &$context = []): obj
$output->setPrivacy($data->getPrivacy());
$output->setWorkspace($data->getWorkspace());

if ($this->hasGroup([
Collection::GROUP_READ,
], $context)) {
$output->owner = $this->transformUser($data->getOwnerId());
}

if ($this->hasGroup(Collection::GROUP_CHILDREN, $context)) {
$maxChildrenLimit = 30;
if (preg_match('#[&?]childrenLimit=(\d+)#', (string) $context['request_uri'], $regs)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace App\Api\OutputTransformer;

use Alchemy\AuthBundle\Repository\UserRepositoryInterface;
use App\Api\Model\Output\UserOutput;
use Symfony\Contracts\Service\Attribute\Required;

trait UserOutputTransformerTrait
{
private UserRepositoryInterface $userRepository;

protected function transformUser(?string $userId): ?UserOutput
{
if (null === $userId) {
return null;
}

$output = new UserOutput();
$output->id = $userId;

$user = $this->userRepository->getUser($userId);
if (null !== $user) {
$output->username = $user['username'];
}

return $output;
}

#[Required]
public function setUserRepository(UserRepositoryInterface $userRepository): void
{
$this->userRepository = $userRepository;
}
}
10 changes: 9 additions & 1 deletion databox/api/src/Entity/Core/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@
#[ApiResource(
shortName: 'asset',
operations: [
new Get(),
new Get(
normalizationContext: [
'groups' => [Asset::GROUP_READ],
]
),
new Delete(security: 'is_granted("DELETE", object)'),
new Put(security: 'is_granted("EDIT", object)'),
new Patch(security: 'is_granted("EDIT", object)'),
Expand Down Expand Up @@ -176,6 +180,9 @@ class Asset extends AbstractUuidEntity implements HighlightableModelInterface, W
#[ORM\OneToMany(mappedBy: 'asset', targetEntity: AssetRendition::class, cascade: ['remove'])]
private ?DoctrineCollection $renditions = null;

#[ORM\OneToMany(mappedBy: 'asset', targetEntity: AssetFileVersion::class, cascade: ['remove'])]
private ?DoctrineCollection $fileVersions = null;

private ?array $highlights = null;

/**
Expand All @@ -202,6 +209,7 @@ public function __construct(float $now = null, int $sequence = null)
$this->renditions = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->attributes = new ArrayCollection();
$this->fileVersions = new ArrayCollection();

/* @var $now float */
$now ??= microtime(true);
Expand Down
2 changes: 1 addition & 1 deletion databox/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"react-pdf": "^5.7.2",
"react-player": "^2.10.1",
"@alchemy/auth": "link:./__lib/auth",
"react-ps": "link:./__lib/react-ps",
"@alchemy/react-ps": "link:./__lib/react-ps",
"react-router-dom": "6",
"react-scripts": "^5.0.1",
"react-select": "^5.3.2",
Expand Down
1 change: 0 additions & 1 deletion databox/client/src/api/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import apiClient from "./api-client";
import {Group, User} from "../types";
import config from "../config";
import {UserPreferences} from "../components/User/Preferences/UserPreferencesContext";

export async function getUsers(): Promise<User[]> {
Expand Down
7 changes: 7 additions & 0 deletions databox/client/src/components/Dialog/Asset/InfoAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ContentTab from "../Tabbed/ContentTab";
import {Divider, MenuList} from "@mui/material";
import KeyIcon from '@mui/icons-material/Key';
import EventIcon from '@mui/icons-material/Event';
import PersonIcon from '@mui/icons-material/Person';
import InfoRow from "../Info/InfoRow";

type Props = {
Expand All @@ -28,6 +29,12 @@ export default function InfoAsset({
icon={<KeyIcon/>}
/>
<Divider/>
<InfoRow
label={'Owner'}
value={data.owner?.username ?? '-'}
copyValue={data.owner?.id}
icon={<PersonIcon/>}
/>
<InfoRow
label={'Date Added'}
value={data.createdAt}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Divider, MenuList} from "@mui/material";
import KeyIcon from '@mui/icons-material/Key';
import EventIcon from '@mui/icons-material/Event';
import InfoRow from "../Info/InfoRow";
import PersonIcon from "@mui/icons-material/Person";

type Props = {
id: string;
Expand All @@ -29,6 +30,12 @@ export default function InfoCollection({
icon={<KeyIcon/>}
/>
<Divider/>
<InfoRow
label={'Owner'}
value={data.owner?.username ?? '-'}
copyValue={data.owner?.id}
icon={<PersonIcon/>}
/>
<InfoRow
label={'Creation date'}
value={data.createdAt}
Expand Down
4 changes: 2 additions & 2 deletions databox/client/src/components/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Suspense} from 'react';
import {User} from "../types";
import {AuthUser} from "../types";
import {UserContext} from "./Security/UserContext";
import Routes from "./Routing/Routes";
import {BrowserRouter} from "react-router-dom";
Expand All @@ -16,7 +16,7 @@ import {
type Props = {};

export default function Root({}: Props) {
const [user, setUser] = React.useState<User | undefined>();
const [user, setUser] = React.useState<AuthUser | undefined>();

React.useEffect(() => {
const onLogin = async () => {
Expand Down
4 changes: 2 additions & 2 deletions databox/client/src/components/Security/UserContext.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import {User} from "../../types";
import {AuthUser} from "../../types";

export type TUserContext = {
user?: User | undefined;
user?: AuthUser | undefined;
logout?: (redirectUri?: string |false) => void | undefined;
}

Expand Down
13 changes: 9 additions & 4 deletions databox/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ type GroupValue = {
type: AttributeType;
}

export type User = {
id: string;
username: string;
}

export interface Asset extends IPermissions<{
canEditAttributes: boolean;
canShare: boolean;
Expand All @@ -34,6 +39,7 @@ export interface Asset extends IPermissions<{
description?: string;
privacy: number;
tags: Tag[];
owner?: User;
workspace: Workspace;
attributes: Attribute[];
collections: Collection[];
Expand Down Expand Up @@ -169,12 +175,10 @@ export interface Tag extends ApiHydraObjectResponse {
workspace: Workspace | string;
}

export interface User {
id: string;
username: string;
export type AuthUser = {
roles: string[];
groups: string[];
}
} & User;

export interface Group {
id: string;
Expand All @@ -192,6 +196,7 @@ export interface Collection extends IPermissions {
privacy: number;
createdAt: string;
updatedAt: string;
owner?: User;
}

export interface Workspace extends IPermissions {
Expand Down
8 changes: 4 additions & 4 deletions databox/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
version "0.0.0"
uid ""

"@alchemy/react-ps@link:./__lib/react-ps":
version "0.0.0"
uid ""

"@alchemy/visual-workflow@link:./__lib/visual-workflow":
version "0.0.0"
uid ""
Expand Down Expand Up @@ -9192,10 +9196,6 @@ react-player@^2.10.1:
prop-types "^15.7.2"
react-fast-compare "^3.0.1"

"react-ps@link:./__lib/react-ps":
version "0.0.0"
uid ""

react-refresh@^0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.11.0.tgz#77198b944733f0f1f1a90e791de4541f9f074046"
Expand Down
1 change: 1 addition & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ services:
- ./:/var/workspace
- ${SSH_AUTH_SOCK}:/ssh-auth-sock
- ${HOME}/.ssh:/home/app/.ssh
- ${HOME}/.composer:/home/app/.composer
- dev_vol:/home/app
- ./configs:/configs
extra_hosts:
Expand Down
9 changes: 5 additions & 4 deletions expose/api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion expose/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"react-images": "^1.1.7",
"react-loader-spinner": "^3.1.4",
"@alchemy/auth": "link:./__lib/auth",
"react-ps": "link:./__lib/react-ps",
"@alchemy/react-ps": "link:./__lib/react-ps",
"react-router-dom": "^5.1.2",
"react-scripts": "3.2.0",
"sass": "^1.44.0",
Expand Down
2 changes: 1 addition & 1 deletion expose/client/src/component/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {getAuthRedirect, unsetAuthRedirect} from "../lib/oauth";
import config from "../lib/config";
import ErrorPage from "./ErrorPage";
import OAuthRedirect from "./OAuthRedirect";
import {DashboardMenu} from "react-ps";
import {DashboardMenu} from "@alchemy/react-ps";
import EmbeddedAsset from "./EmbeddedAsset";
import {oauthClient} from "../lib/api-client";

Expand Down
2 changes: 1 addition & 1 deletion expose/client/src/component/OAuthRedirect.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {useEffectOnce} from "react-ps";
import {useEffectOnce} from "@alchemy/react-ps";
import {OAuthClient} from "@alchemy/auth";
import qs from "querystring";
import {useHistory, useLocation} from "react-router-dom";
Expand Down
Loading

0 comments on commit 0ca6deb

Please sign in to comment.