Add admin to user, add frontend for view-as-user, update readme

This commit is contained in:
Michael Rode
2019-09-02 21:39:53 -05:00
parent b701e8ba62
commit 62de76aca8
12 changed files with 2695 additions and 2378 deletions
+30 -20
View File
@@ -10,6 +10,30 @@ _This is still in development. If you would like to help contribute feel free to
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system
## Installing
Clone the repository
`git clone git@github.com:mjrode/WhatToWatch.git`
cd into the new directory
`cd WhatToWatch`
## Server (run from the root directory)
Install dependencies
`npm install`
Install npx to easily run migrations
`npm install -g npx`
Create database, test database, and run the migrations
`npx sequelize db:create`
`NODE_ENV=test npx sequelize db:create`
`npm run db:reset`
## Prerequisites
* **Required Keys**
#### Rename `example.env` to `.env` and update the test tokens with your tokens
@@ -31,32 +55,18 @@ These instructions will get you a copy of the project up and running on your loc
[TasteDive](https://tastedive.com/read/api)
* `TDAW_API_TOKEN`
## Running the tests
`npm test`
## Installing
Clone the repository
`git clone git@github.com:mjrode/WhatToWatch.git`
cd into the new directory
`cd WhatToWatch`
Install dependencies
`npm install`
Create database and run the migrations
`node server/db/scripts/setup.js`
## Client (run from WhatToWatch/client)
# install dependencies
`npm install`
## Run application
Concurrently run the frontend and backend servers
`npm run dev`
## Running the tests
`npm test`
## Built With
* [Node](www.example.com)
* [React](www.example.com)
+6
View File
@@ -3,6 +3,7 @@ import axios from 'axios';
export const types = {
SET_LOADING: 'set_loading',
FETCH_USER: 'fetch_user',
FETCH_USERS: 'fetch_users',
FETCH_MEDIA_RESPONSE: 'fetch_media_response',
GET_MOST_WATCHED: 'get_most_watched',
ADD_SERIES: 'add_series',
@@ -20,6 +21,11 @@ export const fetchUser = () => async dispatch => {
dispatch({type: types.FETCH_USER, payload: res.data});
};
export const fetchUsers = () => async dispatch => {
const res = await axios.get('/api/admin/current_user');
dispatch({ type: types.FETCH_USERS, payload: res.data });
};
export const fetchPin = () => async dispatch => {
const res = await axios.get('/api/plex/plex-pin');
dispatch({type: types.FETCH_PIN, payload: res.data});
+63
View File
@@ -0,0 +1,63 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link, Redirect } from 'react-router-dom';
import HeroSimple from './HeroSimple';
import * as actions from './../actions';
import Typography from '@material-ui/core/Typography';
class Admin extends Component {
async componentDidMount() {
await this.props.fetchUsers();
console.log('mike--', this.props.auth)
}
render() {
if (!this.props) {
return;
}
if (!this.props.auth.admin) {
console.log('where are my props', this.props)
return <div><p>Checking for admin rights..</p></div>
}
console.log(this.props.auth);
return (
<div>
<HeroSimple />
<div className="row flex-center">
<Typography
variant="h4"
align="center"
color="textSecondary"
paragraph
>
Select a user to login as &nbsp;
<a href="https://plex.tv/link" target="_blank">
plex.com/link.
</a>
</Typography>
</div>
<div className=" flex-center ">
<Typography
variant="h2"
align="center"
color="textSecondary"
paragraph
className="z-depth-2 code"
>
A list of users
</Typography>
</div>
</div>
);
}
}
function mapStateToProps({ auth }) {
console.log('plex props', auth)
return { auth };
}
export default connect(
mapStateToProps,
actions,
)(Admin)
+2
View File
@@ -6,6 +6,7 @@ import * as actions from '../actions';
import Header from './Header';
import Hero from './Hero';
import Plex from './plex/Plex';
import Admin from './Admin';
import PlexPin from './plex/PlexPin';
import SimilarList from './SimilarList';
import PopularList from './PopularList';
@@ -27,6 +28,7 @@ class App extends Component {
<Route exact path="/" component={Hero} />
<Route exact path="/sonarr" component={PlexTokenForm} />
<Route exact path="/plex-pin" component={PlexPin} />
<Route path="/admin" component={Admin} />
<Route path="/most-watched" component={Plex} />
<Route
path="/similar/:show"
+1
View File
@@ -35,6 +35,7 @@ class Plex extends Component {
}
function mapStateToProps({auth, plex}) {
console.log('plex props', auth)
return {auth, mediaResponse: plex.mediaResponse};
}
+3
View File
@@ -4,6 +4,7 @@ export const initialState = {
loading: false,
plexPin: '',
user: '',
users: '',
};
export default function(state = {}, action) {
@@ -11,6 +12,8 @@ export default function(state = {}, action) {
switch (action.type) {
case types.FETCH_USER:
return action.payload || false;
case types.FETCH_USERS:
return action.payload || false;
case types.FETCH_PIN:
return {...state, plexPin: action.payload};
case types.CHECK_PLEX_PIN:
-9
View File
@@ -1,9 +0,0 @@
DATABASE=recommend
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
PLEX_API_TOKEN=testPlexApiToken
TDAW_API_TOKEN=testToken
GOOGLE_CLIENT_ID=testToken
GOOGLE_CLIENT_SECRET=testToken
COOKIE_KEY=testToken
MOVIE_API_KEY=testToken
BIN
View File
Binary file not shown.
+2568 -2348
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -10,7 +10,7 @@
"scripts": {
"test": "cross-env NODE_ENV=test PLEX_API_TOKEN=testPlexApiToken TDAW_API_TOKEN=testTdawToken nyc --reporter=html --reporter=text mocha --require babel-core/register 'test/**/*.test.js' --exit",
"debug:test": "cross-env NODE_ENV=test PLEX_API_TOKEN=testPlexApiToken TDAW_API_TOKEN=testTdawToken nyc --reporter=html --reporter=text mocha --inspect-brk --require babel-core/register 'test/**/*.test.js' --exit",
"db:clean": "npm run db:drop && npm run db:create && npm run db:migrate",
"db:create": "npm run db:create && npm run db:migrate && NODE_ENV=test npm run db:create && npm run db:migrate",
"db:create:test": "NODE_ENV=test npx sequelize db:create",
"db:create-migration": "babel-node ./scripts/db/createMigration",
"db:drop": "babel-node ./scripts/db/drop",
@@ -19,6 +19,7 @@
"dev": "concurrently \"npm run server\" \"npm run client\"",
"debug": "nodemon --exec babel-node --inspect index.js",
"db:reset": "NODE_ENV=test npx sequelize db:migrate:undo:all && NODE_ENV=test npx sequelize db:migrate && npx sequelize db:migrate:undo:all && npx sequelize db:migrate",
"prod:dump": "heroku pg:backups:capture && heroku pg:backups:download",
"start": "babel-node index.js",
"server": "nodemon --exec babel-node index.js",
"client": "npm run start --prefix client",
@@ -0,0 +1,19 @@
module.exports = {
up: function (queryInterface, Sequelize) {
// logic for transforming into the new state
return queryInterface.addColumn(
'Users',
'admin',
Sequelize.BOOLEAN
);
},
down: function (queryInterface, Sequelize) {
// logic for reverting the changes
return queryInterface.removeColumn(
'Users',
'admin'
);
}
}
+1
View File
@@ -13,6 +13,7 @@ module.exports = (sequelize, DataTypes) => {
plexToken: DataTypes.STRING,
sonarrUrl: DataTypes.STRING,
sonarrApiKey: DataTypes.STRING,
admin: DataTypes.BOOLEAN,
},
{},
);