Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
35cb0e8
Roles supporting backend
alexander2001i Apr 22, 2021
1ae24b2
GraphQL role initial additions
alexander2001i Apr 22, 2021
2fd7518
Role assigning
alexander2001i Apr 22, 2021
2799dd1
fix permission getting
watchtower314 Apr 22, 2021
455fa45
Saving changes
alexander2001i Apr 26, 2021
c6d90c2
Importers in progress
alexander2001i Apr 26, 2021
9ef1830
Get admin in order
alexander2001i Apr 27, 2021
51cc4d3
Make the dashboard work again
alexander2001i Apr 28, 2021
2ae6fc9
Statistics
alexander2001i Apr 28, 2021
5a5cf0e
Dashboard statistics
alexander2001i Apr 28, 2021
07eb1da
Common and user statistic counter
alexander2001i Apr 28, 2021
c12e254
Fix admin commons
alexander2001i Apr 28, 2021
098cb20
Proposal join and funding extensions
alexander2001i Apr 29, 2021
b09c06e
Common details page
alexander2001i Apr 29, 2021
eeaa247
Common whitelisting
alexander2001i Apr 29, 2021
e21785c
Common delisting
alexander2001i Apr 29, 2021
e520572
Fix jump redirection problems
alexander2001i Apr 29, 2021
87380b9
Common creation fixes, get proposals query
alexander2001i Apr 29, 2021
0f05da4
Fix proposals page
alexander2001i Apr 29, 2021
8cb4d72
Fix proposal details page
alexander2001i May 5, 2021
1af6145
Proposal votes
alexander2001i May 5, 2021
1183594
Fix user details page
alexander2001i May 5, 2021
a4b3cff
Fix user list page
alexander2001i May 5, 2021
9fb6eef
Save current progress
alexander2001i May 7, 2021
170ff8b
Event notification dynamic link
alexander2001i May 7, 2021
019ad3c
Create command for creating event notification link
alexander2001i May 7, 2021
67911cf
Create graphql infrastructure for creating event notification link
alexander2001i May 7, 2021
6873bb7
Fix the event processing
alexander2001i May 7, 2021
cd055d8
Merge pull request #404 from daostack/CM-403-allow-moderators-to-edit…
alexander2001i May 7, 2021
fe92531
WIP
alexander2001i May 7, 2021
8cac334
Merge pull request #435 from daostack/backend/main
alexander2001i May 7, 2021
a14849e
Merge branch 'main' of https://github.com/daostack/common-monorepo
alexander2001i May 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .run/Admin.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Admin" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/packages/admin/package.json"/>
<command value="run"/>
<scripts>
<script value="dev"/>
</scripts>
<node-interpreter value="project"/>
<envs/>
<method v="2"/>
</configuration>
</component>
13 changes: 7 additions & 6 deletions .run/GraphQL.run.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="GraphQL" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/packages/graphql/package.json" />
<command value="run" />
<package-json value="$PROJECT_DIR$/packages/graphql/package.json"/>
<command value="run"/>
<scripts>
<script value="dev" />
<script value="dev"/>
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
<node-interpreter value="/usr/local/bin/node"/>
<package-manager value="/usr/local/Cellar/yarn/1.22.10/libexec"/>
<envs/>
<method v="2"/>
</configuration>
</component>
5 changes: 5 additions & 0 deletions packages/admin/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
NEXT_PUBLIC_Firebase.ApiKey="AIzaSyClh8UZh-PDyVgwPrHZwURoA4HWuiXUbR8"
NEXT_PUBLIC_Firebase.ProjectId="common-staging-50741"
NEXT_PUBLIC_Firebase.AuthDomain="common-staging-50741.firebaseapp.com"
NEXT_PUBLIC_Firebase.DatabaseUrl="https://common-staging-50741.firebaseio.com"

NEXT_PUBLIC_ADMIN_GRAPH_ENDPOINT=https://us-central1-common-staging-50741.cloudfunctions.net/graph/graphql

NEXT_PUBLIC_Firebase.apiKey=AIzaSyClh8UZh-PDyVgwPrHZwURoA4HWuiXUbR8
Expand Down
7 changes: 6 additions & 1 deletion packages/admin/.env.local
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
NEXT_PUBLIC_ADMIN_GRAPH_ENDPOINT=http://localhost:5003/common-staging-50741/us-central1/graph/graphql
NEXT_PUBLIC_Firebase.ApiKey="AIzaSyClh8UZh-PDyVgwPrHZwURoA4HWuiXUbR8"
NEXT_PUBLIC_Firebase.ProjectId="common-staging-50741"
NEXT_PUBLIC_Firebase.AuthDomain="common-staging-50741.firebaseapp.com"
NEXT_PUBLIC_Firebase.DatabaseUrl="https://common-staging-50741.firebaseio.com"

NEXT_PUBLIC_GraphQl.Endpoint=http://localhost:4000/graphql
6 changes: 6 additions & 0 deletions packages/admin/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NEXT_PUBLIC_Firebase.ApiKey="AIzaSyClh8UZh-PDyVgwPrHZwURoA4HWuiXUbR8"
NEXT_PUBLIC_Firebase.ProjectId="common-staging-50741"
NEXT_PUBLIC_Firebase.AuthDomain="common-staging-50741.firebaseapp.com"
NEXT_PUBLIC_Firebase.DatabaseUrl="https://common-staging-50741.firebaseio.com"

NEXT_PUBLIC_GraphQl.Endpoint=http://localhost:4000/graphql
21 changes: 16 additions & 5 deletions packages/admin/codegen.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
overwrite: true
schema: "http://localhost:5003/common-staging-50741/us-central1/graph/graphql"
documents: "src/**/*.tsx"
schema: "http://localhost:4000/graphql"
documents:
- "src/core/**/*.tsx"
- "src/components/tables/LatestEventsTable.tsx"
- "src/components/CommonSettings.tsx"
- "src/pages/dashboard/index.tsx"
- "src/pages/commons/index.tsx"
- "src/pages/proposals/index.tsx"
- "src/pages/users/index.tsx"
- "src/pages/commons/details/[commonId].tsx"
- "src/pages/proposals/details/[proposalId].tsx"
- "src/pages/users/details/[userId].tsx"
- "src/pages/notifications/**/*.tsx"
generates:
./src/graphql/index.ts:
./src/core/graphql/index.ts:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
./src/graphql/schema.json:
./src/core/graphql/schema.json:
plugins:
- "introspection"
./src/graphql/schema.graphql:
./src/core/graphql/schema.graphql:
plugins:
- schema-ast
config:
Expand Down
6 changes: 5 additions & 1 deletion packages/admin/next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const withImages = require('next-images')

module.exports = withImages()
module.exports = withImages({
future: {
webpack5: true
}
});
3 changes: 3 additions & 0 deletions packages/admin/public/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* {
user-select: none;
}
132 changes: 92 additions & 40 deletions packages/admin/src/components/CommonSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,81 +1,133 @@
import React from 'react';

import { gql } from '@apollo/client';
import { Tooltip, Row, useToasts, Spacer } from '@geist-ui/react';
import { Settings, Award, RefreshCcw, Edit, Trash2 } from '@geist-ui/react-icons';
import { Award, RefreshCcw, Edit, Trash2, Slash, Settings } from '@geist-ui/react-icons';
import { gql } from '@apollo/client';

import { useWhitelistCommonMutation, useDelistCommonMutation } from '@core/graphql';
import { Hoverable } from '@components/Hoverable';
import { Centered } from '@components/Centered';
import { useWhitelistCommonMutation } from '@graphql';

interface ICommonSettingsProps {
commonId: string;
whitelisted: boolean;
refetch: () => any;
}

const WhitelistCommonMutation = gql`
mutation whitelistCommon($commonId: ID!) {
mutation whitelistCommon($commonId: String!) {
whitelistCommon(commonId: $commonId)
}
`;

export const CommonSettings: React.FC<ICommonSettingsProps> = ({ commonId }) => {
const DelistCommonMutation = gql`
mutation delistCommon($commonId: String!) {
delistCommon(commonId: $commonId)
}
`;

export const CommonSettings: React.FC<ICommonSettingsProps> = ({ commonId, whitelisted, refetch }) => {
const [, setToast] = useToasts();

// - Networking
const [whitelistCommon, { data }] = useWhitelistCommonMutation();
const [whitelistCommon, { data: whitelistResult }] = useWhitelistCommonMutation();
const [delistCommon, { data: delistResult }] = useDelistCommonMutation();

// - Actions
const onCommonWhitelisted = async () => {
const onWhitelistCommon = async () => {
await whitelistCommon({
variables: {
commonId
}
});

if (typeof refetch === 'function') {
refetch();
}
};

const onCommonDelist = async () => {
await delistCommon({
variables: {
commonId
}
});

if (typeof refetch === 'function') {
refetch();
}
};

// - Effects
React.useEffect(() => {
if (data?.whitelistCommon) {
if (whitelistResult?.whitelistCommon) {
setToast({
text: 'Common whitelisted!'
});
}
}, [data]);
}, [whitelistResult]);

React.useEffect(() => {
if (delistResult?.delistCommon) {
setToast({
text: 'Common delisted!'
});
}
}, [delistResult]);

return (
<Tooltip
placement="bottomEnd"
trigger="click"
text={(
<div style={{ width: '250px', margin: '.7rem 0' }}>
<Row style={{ cursor: 'pointer' }} onClick={onCommonWhitelisted}>
<Award/>
<Spacer x={.5} />
Whitelist Common
</Row>

<Spacer y={.7} />

<Row style={{ cursor: 'pointer' }}>
<RefreshCcw/>
<Spacer x={.5} />
Refresh Common Members
</Row>

<Spacer y={.7} />

<Row style={{ cursor: 'pointer' }}>
<Edit/>
<Spacer x={.5} />
Edit Common Details
</Row>

<Spacer y={.7} />

<Row style={{ cursor: 'pointer', color: 'red' }}>
<Trash2 />
<Spacer x={.5} />
Delete Common
</Row>
<div style={{ width: '270px', margin: '.3em -0.7em' }}>
<React.Fragment>
<Hoverable>
{whitelisted
? (
<Row style={{ cursor: 'pointer' }} onClick={onCommonDelist}>
<Slash/>
<Spacer x={.5}/>
Delist Common
</Row>
) : (
<Row style={{ cursor: 'pointer' }} onClick={onWhitelistCommon}>
<Award/>
<Spacer x={.5}/>
Whitelist Common
</Row>
)}
</Hoverable>

<Spacer y={.5}/>
</React.Fragment>

<Hoverable>
<Row style={{ cursor: 'pointer' }}>
<RefreshCcw/>
<Spacer x={.5}/>
Refresh Common Members
</Row>
</Hoverable>

<Spacer y={.5}/>

<Hoverable>
<Row style={{ cursor: 'pointer' }}>
<Edit/>
<Spacer x={.5}/>
Edit Common Details
</Row>
</Hoverable>

<Spacer y={.5}/>

<Hoverable>
<Row style={{ cursor: 'pointer', color: 'red' }}>
<Trash2/>
<Spacer x={.5}/>
Delete Common
</Row>
</Hoverable>
</div>
)}
>
Expand Down
43 changes: 18 additions & 25 deletions packages/admin/src/components/HasPermission.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PropsWithChildren } from 'react';

import { usePermissionsContext, useAuthContext } from '@context';
import { useRouter } from 'next/router';
import { useUserContext } from '@core/context';

interface IHasPermissionProps {
permission: string;
Expand All @@ -10,43 +10,40 @@ interface IHasPermissionProps {
}

export const HasPermission: React.FC<PropsWithChildren<IHasPermissionProps>> = ({ children, permission, redirect }) => {
const permissionsContext = usePermissionsContext();
const authContext = useAuthContext();
const router = useRouter();
const userContext = useUserContext();

const hasPermission = (permission: string): boolean => {
let hasPermission = false;

if (permissionsContext.loaded) {
if (userContext.loaded) {
const permissions = userContext.permissions;

console.log(permissions);

if (permission.includes('*')) {
hasPermission = permissionsContext.permissions
.some((userPermission) => matchRuleExpl(userPermission, permission));
hasPermission = permissions.some((userPermission) =>
matchRuleExpl(userPermission, permission));
} else {
hasPermission = permissionsContext.permissions.includes(permission);
hasPermission = permissions.includes(permission);
}
}

console.debug(`Permission check for [${permission}]: ${hasPermission}`);

if (!hasPermission && redirect) {
if (authContext.authenticated) {
router.push({
if (!hasPermission && userContext.loaded && redirect) {
router
.push({
pathname: '/error/unauthorized',
query: {
redirected: true,
redirectedFrom: router.pathname,
failedPermission: permission
}
})
.then(() => {
console.log('Redirected unauthorized request');
});
} else {
router.push({
pathname: '/auth',
query: {
redirected: true,
redirectedFrom: router.pathname
}
});
}
}

return true;
Expand All @@ -72,13 +69,9 @@ export const HasPermission: React.FC<PropsWithChildren<IHasPermissionProps>> = (
};


return (
return hasPermission(permission) && (
<React.Fragment>
{permissionsContext.loaded && hasPermission(permission) && (
<React.Fragment>
{children}
</React.Fragment>
)}
{children}
</React.Fragment>
);
};
Loading