Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 29 additions & 4 deletions generators/app/templates/package-lock.json

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

11 changes: 11 additions & 0 deletions generators/app/templates/public/locales/en-US/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{
"appPermission": {
"message": "The application permissions are not properly set. Please add additional permissions and try again",
"link": {
"label": "Learn more",
"href": "https://solidsdk.inrupt.net/public/general/en/app-permissions.html"
}
},
"notifications": {
"success": "Éxito",
"error": "Error"
},
"login": {
"title": "Hi! Welcome to Solid.",
"loginTitle": "Log in",
Expand Down
7 changes: 7 additions & 0 deletions generators/app/templates/public/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"appPermission": {
"message": "The application permissions are not properly set. Please add additional permissions and try again",
"link": {
"label": "Learn more",
"href": "https://solidsdk.inrupt.net/public/general/en/app-permissions.html"
}
},
"notifications": {
"success": "Success",
"error": "Error"
Expand Down
11 changes: 11 additions & 0 deletions generators/app/templates/public/locales/es/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{
"appPermission": {
"message": "La aplicacion necesita todos los permisos para funcionar.",
"link": {
"label": "Learn more",
"href": "https://solidsdk.inrupt.net/public/general/es/app-permissions.html"
}
},
"notifications": {
"success": "Éxito",
"error": "Error"
},
"login": {
"title": "Hola! Bienvenido a Solid.",
"loginTitle": "Iniciar sesión",
Expand Down
100 changes: 68 additions & 32 deletions generators/app/templates/src/layouts/PrivateLayout/private.layout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import React from 'react';
import React, { useCallback, useEffect } from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import { withAuthorization } from '@inrupt/solid-react-components';
import { useTranslation } from 'react-i18next';
import {
withAuthorization,
AppPermission,
AccessControlList
} from '@inrupt/solid-react-components';
import { AuthNavBar, Footer } from '@components';
import { errorToaster, checkAppPermissions } from '@utils';
import styled from 'styled-components';

const Container = styled.div`
Expand All @@ -18,35 +24,65 @@ const Content = styled.div`
overflow-y: auto;
`;

const PrivateLayout = ({ routes, webId, location, history, ...rest }) => (
<React.Fragment>
<Container>
<Route
{...rest}
component={({ history }) => (
<Content className="contentApp">
<AuthNavBar {...{ location, webId, history }} />
<Switch>
{routes.map(route => {
const { component: RouteComponent } = route;
return (
<Route
key={route.id}
path={route.path}
render={routerProps => <RouteComponent {...routerProps} webId={webId} />}
webId={webId}
exact
/>
);
})}
<Redirect to="/404" />
</Switch>
</Content>
)}
/>
<Footer />
</Container>
</React.Fragment>
);
const PrivateLayout = ({ routes, webId, location, history, ...rest }) => {
const { t } = useTranslation();
/**
* SDK app will need all the permissions by the user pod so
* we check these permissions to work without any issues.
*/
const checkPermissions = useCallback(async () => {
/**
* Get permissions from trustedApp.
*/
const userApp = await AppPermission.checkPermissions(webId);
/**
* Get modes permissions from solid-react-components
*/
const permissions = AccessControlList.MODES;
const { APPEND, READ, WRITE, CONTROL } = permissions;

if (!checkAppPermissions(userApp.permissions, [APPEND, READ, WRITE, CONTROL])) {
errorToaster(t('appPermission.message'), t('notifications.error'), {
label: t('appPermission.link.label'),
href: t('appPermission.link.href')
});
}
}, [webId]);

useEffect(() => {
if (webId) checkPermissions();
}, [webId]);

return (
<React.Fragment>
<Container>
<Route
{...rest}
component={({ history }) => (
<Content className="contentApp">
<AuthNavBar {...{ location, webId, history }} />
<Switch>
{routes.map(route => {
const { component: RouteComponent } = route;
return (
<Route
key={route.id}
path={route.path}
render={routerProps => <RouteComponent {...routerProps} webId={webId} />}
webId={webId}
exact
/>
);
})}
<Redirect to="/404" />
</Switch>
</Content>
)}
/>
<Footer />
</Container>
</React.Fragment>
);
};

export default withAuthorization(PrivateLayout);
7 changes: 7 additions & 0 deletions generators/app/templates/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ function getUserNameByUrl(webId) {
return 'unknown';
}

function checkAppPermissions(userAppPermissions, appPermissions) {
const userAppPermission = userAppPermissions.sort().toString();
const appPermission = appPermissions.sort().toString();
return userAppPermission === appPermission;
}

export {
media,
expandedProperty,
Expand All @@ -34,5 +40,6 @@ export {
errorToaster,
buildPathFromWebId,
getUserNameByUrl,
checkAppPermissions,
notification
};