Spotify.access will be checker for full access
This commit is contained in:
@ -15,7 +15,7 @@ class FollowButton extends React.Component{
|
||||
}
|
||||
|
||||
componentDidMount(){
|
||||
if (this.props.spotify_authorized && this.props.uri){
|
||||
if (this.props.spotify_access == 'full' && this.props.uri){
|
||||
this.props.spotifyActions.following(this.props.uri)
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,7 @@ class FollowButton extends React.Component{
|
||||
}
|
||||
|
||||
render(){
|
||||
if (!this.props.spotify_authorized || !this.props.uri){
|
||||
if (this.props.spotify_access !== 'full' || !this.props.uri){
|
||||
return false
|
||||
}
|
||||
|
||||
@ -56,7 +56,8 @@ class FollowButton extends React.Component{
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
load_queue: state.ui.load_queue,
|
||||
spotify_authorized: state.spotify.authorized
|
||||
spotify_access: state.spotify.access,
|
||||
spotify_authorized: state.spotify.authorization
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -77,7 +77,7 @@ class Services extends React.Component{
|
||||
var user = null
|
||||
if (this.props.spotify.me && this.props.spotify.authorization && this.props.spotify.authentication_provider == 'http_api'){
|
||||
user = this.props.spotify.me
|
||||
} else if (this.props.spotify.backend_username && this.props.spotify.backend_username){
|
||||
} else if (this.props.spotify.backend_username){
|
||||
if (this.props.core.users && this.props.core.users['spotify:user:'+this.props.spotify.backend_username] !== undefined){
|
||||
user = this.props.core.users['spotify:user:'+this.props.spotify.backend_username]
|
||||
}
|
||||
@ -114,7 +114,7 @@ class Services extends React.Component{
|
||||
}
|
||||
|
||||
renderSendAuthorizationButton(){
|
||||
if (!this.props.spotify.authorized) return null
|
||||
if (!this.props.spotify.authorization) return null
|
||||
|
||||
return (
|
||||
<button onClick={e => this.props.uiActions.openModal('send_authorization', {}) }>
|
||||
@ -128,72 +128,70 @@ class Services extends React.Component{
|
||||
<div>
|
||||
<h4 className="underline">Spotify (access {this.props.spotify.access})</h4>
|
||||
{!this.props.uri_schemes.includes('spotify:') ? <span className="red-text">Mopidy-Spotify not running</span> : null}
|
||||
<form>
|
||||
|
||||
<div className="field">
|
||||
<div className="name">Country</div>
|
||||
<div className="input">
|
||||
<input
|
||||
type="text"
|
||||
onChange={e => this.setState({ spotify_country: e.target.value })}
|
||||
onFocus={e => this.setState({input_in_focus: 'spotify_country'})}
|
||||
onBlur={e => this.setSpotifyConfig() }
|
||||
value={ this.state.spotify_country } />
|
||||
</div>
|
||||
<div className="field">
|
||||
<div className="name">Country</div>
|
||||
<div className="input">
|
||||
<input
|
||||
type="text"
|
||||
onChange={e => this.setState({ spotify_country: e.target.value })}
|
||||
onFocus={e => this.setState({input_in_focus: 'spotify_country'})}
|
||||
onBlur={e => this.setSpotifyConfig() }
|
||||
value={ this.state.spotify_country } />
|
||||
</div>
|
||||
<div className="field">
|
||||
<div className="name">Locale</div>
|
||||
<div className="input">
|
||||
<input
|
||||
type="text"
|
||||
onChange={e => this.setState({ spotify_locale: e.target.value })}
|
||||
onFocus={e => this.setState({input_in_focus: 'spotify_locale'})}
|
||||
onBlur={e => this.setSpotifyConfig() }
|
||||
value={this.state.spotify_locale} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<div className="name">Locale</div>
|
||||
<div className="input">
|
||||
<input
|
||||
type="text"
|
||||
onChange={e => this.setState({ spotify_locale: e.target.value })}
|
||||
onFocus={e => this.setState({input_in_focus: 'spotify_locale'})}
|
||||
onBlur={e => this.setSpotifyConfig() }
|
||||
value={this.state.spotify_locale} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="field radio">
|
||||
<span className="name">Authentication provider</span>
|
||||
<div className="input">
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
name="spotify_authentication_provider"
|
||||
value="backend"
|
||||
checked={this.props.spotify.authentication_provider == 'backend'}
|
||||
onChange={e => this.setProvider(e.target.value)}
|
||||
/>
|
||||
<span className="label">Mopidy-Spotify</span>
|
||||
</label>
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
name="spotify_authentication_provider"
|
||||
value="http_api"
|
||||
checked={this.props.spotify.authentication_provider == 'http_api' }
|
||||
onChange={e => this.setProvider(e.target.value)}
|
||||
/>
|
||||
<span className="label">HTTP API</span>
|
||||
</label>
|
||||
<div className="field radio">
|
||||
<span className="name">Authentication provider</span>
|
||||
<div className="input">
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
name="spotify_authentication_provider"
|
||||
value="backend"
|
||||
checked={this.props.spotify.authentication_provider == 'backend'}
|
||||
onChange={e => this.setProvider(e.target.value)}
|
||||
/>
|
||||
<span className="label">Mopidy-Spotify</span>
|
||||
</label>
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
name="spotify_authentication_provider"
|
||||
value="http_api"
|
||||
checked={this.props.spotify.authentication_provider == 'http_api' }
|
||||
onChange={e => this.setProvider(e.target.value)}
|
||||
/>
|
||||
<span className="label">HTTP API</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{this.props.spotify.authentication_provider == 'http_api' ? <div className="field">
|
||||
<div className="name">Authentication</div>
|
||||
<div className="input">
|
||||
<SpotifyAuthenticationFrame />
|
||||
{ this.renderSendAuthorizationButton() }
|
||||
</div>
|
||||
</div> : null}
|
||||
<div className="field current-user">
|
||||
<div className="name">Current user</div>
|
||||
<div className="input">
|
||||
<div className="text">
|
||||
{ this.renderSpotifyUser() }
|
||||
</div>
|
||||
</div>
|
||||
{this.props.spotify.authentication_provider == 'http_api' ? <div className="field">
|
||||
<div className="name">Authentication</div>
|
||||
<div className="input">
|
||||
<SpotifyAuthenticationFrame />
|
||||
{ this.renderSendAuthorizationButton() }
|
||||
</div>
|
||||
</div> : null}
|
||||
<div className="field current-user">
|
||||
<div className="name">Current user</div>
|
||||
<div className="input">
|
||||
<div className="text">
|
||||
{ this.renderSpotifyUser() }
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
spotify_enabled: state.spotify.enabled,
|
||||
spotify_access: state.spotify.access,
|
||||
spotify_connected: state.spotify.connected,
|
||||
spotify_authorized: state.spotify.authorized,
|
||||
spotify_authorized: state.spotify.authorization,
|
||||
dragger: state.ui.dragger
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ class SpotifyAuthenticationFrame extends React.Component{
|
||||
)
|
||||
} else if (this.props.authorized){
|
||||
return (
|
||||
<button className="destructive" onClick={() => this.props.spotifyActions.authorizationRevoked()}>Log out</button>
|
||||
<button className="destructive" onClick={() => this.props.spotifyActions.revokeAuthorization()}>Log out</button>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
@ -147,7 +147,7 @@ class SpotifyAuthenticationFrame extends React.Component{
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
authorization_url: state.spotify.authorization_url,
|
||||
authorized: state.spotify.authorized,
|
||||
authorized: state.spotify.authorization,
|
||||
authorizing: state.spotify.authorizing,
|
||||
refreshing_token: state.spotify.refreshing_token
|
||||
}
|
||||
|
||||
@ -201,7 +201,7 @@ const CoreMiddleware = (function(){
|
||||
break
|
||||
|
||||
case 'spotify':
|
||||
if (store.getState().spotify.authorized && store.getState().spotify.me){
|
||||
if (store.getState().spotify.authorization && store.getState().spotify.me){
|
||||
playlist.can_edit = (helpers.getFromUri('playlistowner',playlist.uri) == store.getState().spotify.me.id)
|
||||
}
|
||||
}
|
||||
@ -225,7 +225,7 @@ const CoreMiddleware = (function(){
|
||||
break
|
||||
|
||||
case 'spotify':
|
||||
if (store.getState().spotify.authorized && store.getState().spotify.me){
|
||||
if (store.getState().spotify.authorization && store.getState().spotify.me){
|
||||
playlist.can_edit = (helpers.getFromUri('playlistowner',playlist.uri) == store.getState().spotify.me.id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,10 +83,10 @@ const localstorageMiddleware = (function(){
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_GRANTED':
|
||||
var spotify = JSON.parse( localStorage.getItem('spotify') );
|
||||
if( !spotify ) spotify = {};
|
||||
Object.assign(
|
||||
spotify,{
|
||||
authorized: true,
|
||||
spotify = Object.assign(
|
||||
{},
|
||||
(spotify ? spotify : {}),
|
||||
{
|
||||
authorization: action.data,
|
||||
access_token: action.data.access_token,
|
||||
refresh_token: action.data.refresh_token,
|
||||
@ -97,16 +97,19 @@ const localstorageMiddleware = (function(){
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_REVOKED':
|
||||
console.log('local',action)
|
||||
var spotify = JSON.parse( localStorage.getItem('spotify') );
|
||||
if( !spotify ) spotify = {};
|
||||
Object.assign(
|
||||
spotify,{
|
||||
authorized: false,
|
||||
spotify = Object.assign(
|
||||
{},
|
||||
(spotify ? spotify : {}),
|
||||
{
|
||||
authorization: false,
|
||||
access_token: false,
|
||||
refresh_token: false,
|
||||
token_expiry: false
|
||||
}
|
||||
);
|
||||
console.log(spotify)
|
||||
localStorage.setItem('spotify', JSON.stringify(spotify));
|
||||
break;
|
||||
|
||||
|
||||
@ -335,6 +335,12 @@ const PusherMiddleware = (function(){
|
||||
authorization_url: (action.config.authorization_url ? action.config.authorization_url : null),
|
||||
backend_username: (action.config.spotify_username ? action.config.spotify_username : null)
|
||||
}))
|
||||
|
||||
// Get our backend_username user
|
||||
if (store.getState().spotify.access !== 'none' && (!store.getState().core.users || !store.getState().core.users[action.config.spotify_username])){
|
||||
store.dispatch(spotifyActions.getUser(action.config.spotify_username))
|
||||
}
|
||||
|
||||
next( action )
|
||||
break
|
||||
|
||||
|
||||
@ -112,7 +112,7 @@ function getToken( dispatch, getState ){
|
||||
function refreshToken( dispatch, getState ){
|
||||
return new Promise( (resolve, reject) => {
|
||||
|
||||
if (getState().spotify.authorized){
|
||||
if (getState().spotify.authorization && getState().spotify.authentication_provider == 'http_api'){
|
||||
|
||||
$.ajax({
|
||||
method: 'GET',
|
||||
@ -204,7 +204,7 @@ export function authorizationGranted( data ){
|
||||
return { type: 'SPOTIFY_AUTHORIZATION_GRANTED', data: data }
|
||||
}
|
||||
|
||||
export function authorizationRevoked(){
|
||||
export function revokeAuthorization(){
|
||||
return { type: 'SPOTIFY_AUTHORIZATION_REVOKED' }
|
||||
}
|
||||
|
||||
|
||||
@ -68,7 +68,7 @@ const SpotifyMiddleware = (function(){
|
||||
break
|
||||
|
||||
case 'SPOTIFY_CREATE_PLAYLIST':
|
||||
if( !store.getState().spotify.authorized ){
|
||||
if( !store.getState().spotify.authorization ){
|
||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||
return
|
||||
}
|
||||
@ -78,7 +78,7 @@ const SpotifyMiddleware = (function(){
|
||||
case 'SPOTIFY_REMOVE_PLAYLIST_TRACKS':
|
||||
var playlist = state.core.playlists[action.key]
|
||||
|
||||
if( !store.getState().spotify.authorized ){
|
||||
if( !store.getState().spotify.authorization ){
|
||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||
return
|
||||
}
|
||||
@ -92,7 +92,7 @@ const SpotifyMiddleware = (function(){
|
||||
|
||||
case 'SPOTIFY_ADD_PLAYLIST_TRACKS':
|
||||
|
||||
if( !store.getState().spotify.authorized ){
|
||||
if( !store.getState().spotify.authorization ){
|
||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||
return
|
||||
}
|
||||
@ -102,7 +102,7 @@ const SpotifyMiddleware = (function(){
|
||||
|
||||
case 'SPOTIFY_REORDER_PLAYLIST_TRACKS':
|
||||
|
||||
if( !store.getState().spotify.authorized ){
|
||||
if( !store.getState().spotify.authorization ){
|
||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||
return
|
||||
}
|
||||
@ -117,7 +117,7 @@ const SpotifyMiddleware = (function(){
|
||||
|
||||
case 'SPOTIFY_SAVE_PLAYLIST':
|
||||
|
||||
if( !store.getState().spotify.authorized ){
|
||||
if( !store.getState().spotify.authorization ){
|
||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||
return
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ export default function reducer(spotify = {}, action){
|
||||
var spotify = Object.assign({},spotify,action.config)
|
||||
|
||||
let access = 'none'
|
||||
if (spotify.authentication_provider == 'http_api' && spotify.authorized){
|
||||
if (spotify.authentication_provider == 'http_api' && spotify.authorization){
|
||||
access = 'full'
|
||||
} else if (spotify.authentication_provider == 'backend' && spotify.backend_username){
|
||||
access = 'limited'
|
||||
@ -27,7 +27,7 @@ export default function reducer(spotify = {}, action){
|
||||
return spotify
|
||||
|
||||
case 'PUSHER_SPOTIFY_TOKEN':
|
||||
if( spotify.authorized ) return spotify;
|
||||
if( spotify.authorization ) return spotify;
|
||||
return Object.assign({}, spotify, {
|
||||
authorizing: false,
|
||||
authorization: false,
|
||||
|
||||
@ -173,7 +173,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
album: (state.core.albums && typeof(state.core.albums[ownProps.params.uri]) !== 'undefined' ? state.core.albums[ownProps.params.uri] : false ),
|
||||
albums: state.core.albums,
|
||||
library_albums: state.core.library_albums,
|
||||
spotify_authorized: state.spotify.authorized,
|
||||
spotify_authorized: state.spotify.authorization,
|
||||
mopidy_connected: state.mopidy.connected
|
||||
};
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
artists: (state.core.artists ? state.core.artists : []),
|
||||
library_artists: (state.core.library_artists ? state.core.library_artists : []),
|
||||
albums: (state.core.albums ? state.core.albums : []),
|
||||
spotify_authorized: state.spotify.authorized,
|
||||
spotify_authorized: state.spotify.authorization,
|
||||
mopidy_connected: state.mopidy.connected
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,7 +217,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
playlist: (state.core.playlists && typeof(state.core.playlists[uri]) !== 'undefined' ? state.core.playlists[uri] : false ),
|
||||
library_playlists: state.core.library_playlists,
|
||||
mopidy_connected: state.mopidy.connected,
|
||||
spotify_authorized: state.spotify.authorized,
|
||||
spotify_authorized: state.spotify.authorization,
|
||||
spotify_userid: state.spotify.me.id
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ class User extends React.Component{
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
load_queue: state.ui.load_queue,
|
||||
spotify_authorized: state.spotify.authorized,
|
||||
spotify_authorized: state.spotify.authorization,
|
||||
spotify_authentication_provider: state.spotify.authentication_provider,
|
||||
spotify_backend_username: state.spotify.backend_username,
|
||||
me: state.spotify.me,
|
||||
|
||||
@ -268,7 +268,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
artists: (state.core.artists ? state.core.artists : []),
|
||||
tracks: (state.core.tracks ? state.core.tracks : []),
|
||||
genres: (state.core.genres ? state.core.genres : []),
|
||||
authorized: state.spotify.authorized,
|
||||
authorized: state.spotify.authorization,
|
||||
load_queue: state.ui.load_queue,
|
||||
quick_search_results: (state.spotify.quick_search_results ? state.spotify.quick_search_results : {artists: [], tracks: []}),
|
||||
recommendations: (state.spotify.recommendations ? state.spotify.recommendations : {}),
|
||||
|
||||
Reference in New Issue
Block a user