diff --git a/api/src/resolvers/scanner.js b/api/src/resolvers/scanner.js index 74d19bfa..fe3d300c 100644 --- a/api/src/resolvers/scanner.js +++ b/api/src/resolvers/scanner.js @@ -5,7 +5,7 @@ const Mutation = { if (ctx.scanner.isRunning) { return { finished: false, - error: true, + success: false, errorMessage: 'Scanner already running', } } @@ -14,8 +14,9 @@ const Mutation = { return { finished: false, - error: false, + success: true, progress: 0, + errorMessage: null, } }, } diff --git a/api/src/resolvers/users.js b/api/src/resolvers/users.js index bf327de8..3b7b74c2 100644 --- a/api/src/resolvers/users.js +++ b/api/src/resolvers/users.js @@ -1,6 +1,7 @@ import jwt from 'jsonwebtoken' import uuid from 'uuid' import fs from 'fs-extra' +import { neo4jgraphql } from 'neo4j-graphql-js' const Mutation = { async authorizeUser(root, args, ctx, info) { @@ -87,6 +88,20 @@ const Mutation = { export const registerUser = Mutation.registerUser +const Query = { + myUser(root, args, ctx, info) { + let customArgs = { + filter: {}, + ...args, + } + + customArgs.filter.id = ctx.user.id + + return neo4jgraphql(root, customArgs, ctx, info) + }, +} + export default { Mutation, + Query, } diff --git a/api/src/scanner/Scanner.js b/api/src/scanner/Scanner.js index e5cdeafa..c2a3d711 100644 --- a/api/src/scanner/Scanner.js +++ b/api/src/scanner/Scanner.js @@ -37,7 +37,7 @@ class PhotoScanner { scannerStatusUpdate: { progress: (this.finishedImages / this.imagesToProgress) * 100, finished: false, - error: false, + success: true, errorMessage: '', }, }) @@ -77,7 +77,7 @@ class PhotoScanner { scannerStatusUpdate: { progress: 0, finished: false, - error: false, + success: true, errorMessage: '', }, }) @@ -89,7 +89,7 @@ class PhotoScanner { scannerStatusUpdate: { progress: 0, finished: false, - error: true, + success: false, errorMessage: error.message, }, }) @@ -104,7 +104,7 @@ class PhotoScanner { scannerStatusUpdate: { progress: 100, finished: true, - error: false, + success: true, errorMessage: '', }, }) diff --git a/api/src/schema.graphql b/api/src/schema.graphql index f7f58361..0e42a481 100644 --- a/api/src/schema.graphql +++ b/api/src/schema.graphql @@ -111,6 +111,8 @@ type Mutation { type Query { siteInfo: SiteInfo + myUser: User @isAuthenticated + myAlbums: [Album] @isAuthenticated album(id: ID): Album @isAuthenticated diff --git a/ui/src/AuthorizedRoute.js b/ui/src/AuthorizedRoute.js index 05556d14..4e73d93e 100644 --- a/ui/src/AuthorizedRoute.js +++ b/ui/src/AuthorizedRoute.js @@ -1,7 +1,17 @@ import React from 'react' import { Route, Redirect } from 'react-router-dom' +import gql from 'graphql-tag' +import { Query } from 'react-apollo' -const AuthorizedRoute = ({ component: Component, ...props }) => { +const adminQuery = gql` + query adminQuery { + myUser { + admin + } + } +` + +const AuthorizedRoute = ({ component: Component, admin, ...props }) => { const token = localStorage.getItem('token') let unauthorizedRedirect = null @@ -9,12 +19,30 @@ const AuthorizedRoute = ({ component: Component, ...props }) => { unauthorizedRedirect = } + let adminRedirect = null + if (token && admin) { + adminRedirect = ( + + {({ loading, error, data }) => { + if (error) alert(error) + + if (data && data.myUser && !data.myUser.admin) { + return + } + + return null + }} + + ) + } + return ( ( <> {unauthorizedRedirect} + {adminRedirect} > )} diff --git a/ui/src/Layout.js b/ui/src/Layout.js index 34ddbf54..f58bd6a2 100644 --- a/ui/src/Layout.js +++ b/ui/src/Layout.js @@ -2,6 +2,16 @@ import React, { Component } from 'react' import styled from 'styled-components' import { NavLink } from 'react-router-dom' import { Icon } from 'semantic-ui-react' +import { Query } from 'react-apollo' +import gql from 'graphql-tag' + +const adminQuery = gql` + query adminQuery { + myUser { + admin + } + } +` const Container = styled.div` height: 100%; @@ -86,6 +96,20 @@ class Layout extends Component { Albums + + {({ loading, error, data }) => { + if (data && data.myUser && data.myUser.admin) { + return ( + + + Settings + + ) + } + + return null + }} + {this.props.children} diff --git a/ui/src/Pages/PhotosPage/PhotosPage.js b/ui/src/Pages/PhotosPage/PhotosPage.js index 2b75be7e..5983bbed 100644 --- a/ui/src/Pages/PhotosPage/PhotosPage.js +++ b/ui/src/Pages/PhotosPage/PhotosPage.js @@ -7,7 +7,7 @@ import PhotoSidebar from '../../components/sidebar/PhotoSidebar' const photoQuery = gql` query allPhotosPage { - myAlbums(orderBy: title_asc) { + myAlbums(orderBy: title_asc, filter: { photos_not: null }) { title id photos(orderBy: title_desc, first: 12) { diff --git a/ui/src/Pages/SettingsPage/SettingsPage.js b/ui/src/Pages/SettingsPage/SettingsPage.js new file mode 100644 index 00000000..b3cfe7f2 --- /dev/null +++ b/ui/src/Pages/SettingsPage/SettingsPage.js @@ -0,0 +1,42 @@ +import React from 'react' +import Layout from '../../Layout' + +import { Button, Icon } from 'semantic-ui-react' +import { Mutation } from 'react-apollo' +import gql from 'graphql-tag' + +const scanMutation = gql` + mutation scanAllMutation { + scanAll { + success + errorMessage + } + } +` + +const SettingsPage = () => ( + + Settings + + {(scan, { data }) => ( + <> + Scanner + { + scan() + }} + disabled={data && data.scanAll && data.scanAll.success} + > + + Scan All + + Scan for new images for all users + > + )} + + +) + +export default SettingsPage diff --git a/ui/src/Routes.js b/ui/src/Routes.js index 108552da..a9e5ccb0 100644 --- a/ui/src/Routes.js +++ b/ui/src/Routes.js @@ -2,6 +2,7 @@ import React from 'react' import { Route, Switch, Redirect } from 'react-router-dom' import { Loader } from 'semantic-ui-react' +import Layout from './Layout' const AlbumsPage = React.lazy(() => import('./Pages/AllAlbumsPage/AlbumsPage')) const AlbumPage = React.lazy(() => import('./Pages/AlbumPage/AlbumPage')) @@ -13,17 +14,28 @@ const InitialSetupPage = React.lazy(() => import('./Pages/LoginPage/InitialSetupPage') ) +const SettingsPage = React.lazy(() => + import('./Pages/SettingsPage/SettingsPage') +) + class Routes extends React.Component { render() { return ( - Loading page}> + + Loading page + + } + > - } /> + + } /> Page not found} />
Scan for new images for all users