Removing authorized, just use authorization
This commit is contained in:
@ -272,7 +272,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
processes: (state.ui.processes ? state.ui.processes : {}),
|
||||
load_queue: (state.ui.load_queue ? state.ui.load_queue : {}),
|
||||
mopidy_connected: state.mopidy.connected,
|
||||
spotify_authorized: state.spotify.authorized,
|
||||
spotify_authorized: state.spotify.authorization,
|
||||
play_state: state.mopidy.play_state,
|
||||
play_time_position: parseInt(state.mopidy.time_position),
|
||||
mute: state.mopidy.mute,
|
||||
|
||||
2
src/js/bootstrap.js
vendored
2
src/js/bootstrap.js
vendored
@ -61,8 +61,8 @@ var initialState = {
|
||||
track: {}
|
||||
},
|
||||
spotify: {
|
||||
enabled: true,
|
||||
connected: false,
|
||||
access: 'none',
|
||||
authentication_provider: 'backend',
|
||||
me: false,
|
||||
autocomplete_results: {},
|
||||
|
||||
@ -582,7 +582,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
library_albums: state.core.library_albums,
|
||||
library_playlists: state.core.library_playlists,
|
||||
playlists: state.core.playlists,
|
||||
spotify_authorized: state.spotify.authorized
|
||||
spotify_authorized: state.spotify.authorization
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
playlists: state.ui.playlists,
|
||||
context_menu: state.ui.context_menu,
|
||||
mopidy_connected: state.mopidy.connected,
|
||||
spotify_authorized: state.spotify.authorized
|
||||
spotify_authorized: state.spotify.authorization
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -75,10 +75,10 @@ class Services extends React.Component{
|
||||
renderSpotifyUser(){
|
||||
|
||||
var user = null
|
||||
if (this.props.spotify.me && this.props.spotify.authorized){
|
||||
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){
|
||||
if (this.props.core.users && typeof(this.props.core.users['spotify:user:'+this.props.spotify.backend_username]) !== 'undefined'){
|
||||
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]
|
||||
}
|
||||
}
|
||||
@ -89,7 +89,15 @@ class Services extends React.Component{
|
||||
<Thumbnail circle={true} size="small" images={user.images} />
|
||||
<span className="user-name">
|
||||
{user.display_name ? user.display_name : user.id}
|
||||
{!this.props.spotify.authorized ? <span className="grey-text"> (limited access)</span> : null}
|
||||
</span>
|
||||
</Link>
|
||||
)
|
||||
} else if (this.props.spotify.backend_username){
|
||||
return (
|
||||
<Link className="user" to={global.baseURL+'user/spotify:user:'+this.props.spotify.backend_username}>
|
||||
<Thumbnail circle={true} size="small" />
|
||||
<span className="user-name">
|
||||
{this.props.spotify.backend_username}
|
||||
</span>
|
||||
</Link>
|
||||
)
|
||||
@ -98,8 +106,7 @@ class Services extends React.Component{
|
||||
<Link className="user">
|
||||
<Thumbnail circle={true} size="small" />
|
||||
<span className="user-name">
|
||||
Default user
|
||||
<span className="grey-text"> (limited access)</span>
|
||||
Unknown
|
||||
</span>
|
||||
</Link>
|
||||
)
|
||||
@ -119,32 +126,10 @@ class Services extends React.Component{
|
||||
render(){
|
||||
return (
|
||||
<div>
|
||||
<h4 className="underline">Spotify</h4>
|
||||
<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 radio">
|
||||
<span className="name">Authentication provider</span>
|
||||
<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 className="field">
|
||||
<div className="name">Country</div>
|
||||
<div className="input">
|
||||
@ -167,22 +152,48 @@ class Services extends React.Component{
|
||||
value={this.state.spotify_locale} />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div className="field current-user">
|
||||
<div className="name">Current user</div>
|
||||
<div className="input">
|
||||
<div className="text">
|
||||
{ this.renderSpotifyUser() }
|
||||
|
||||
<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>
|
||||
</div>
|
||||
<div className="field">
|
||||
<div className="name">Authentication</div>
|
||||
<div className="input">
|
||||
<SpotifyAuthenticationFrame />
|
||||
{ this.renderSendAuthorizationButton() }
|
||||
{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>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -197,6 +208,7 @@ class Services extends React.Component{
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
uri_schemes: (state.mopidy.uri_schemes ? state.mopidy.uri_schemes : []),
|
||||
core: state.core,
|
||||
spotify: state.spotify
|
||||
}
|
||||
|
||||
@ -68,18 +68,14 @@ class Sidebar extends React.Component{
|
||||
<Icon name="playlist" />
|
||||
Playlists
|
||||
</Link>
|
||||
<Link className={this.linkClassName('library/artists')} disabled={!this.props.spotify_authorized} to={this.props.spotify_authorized ? global.baseURL+"library/artists" : null}>
|
||||
<Link className={this.linkClassName('library/artists')} disabled={this.props.spotify_access != 'full'} to={this.props.spotify_authorized ? global.baseURL+"library/artists" : null}>
|
||||
<Icon name="mic" />
|
||||
Artists
|
||||
</Link>
|
||||
<Link className={this.linkClassName('library/albums')} disabled={!this.props.spotify_authorized} to={this.props.spotify_authorized ? global.baseURL+"library/albums" : null}>
|
||||
<Link className={this.linkClassName('library/albums')} disabled={this.props.spotify_access != 'full'} to={this.props.spotify_authorized ? global.baseURL+"library/albums" : null}>
|
||||
<Icon name="cd" />
|
||||
Albums
|
||||
</Link>
|
||||
<Link className={this.linkClassName('library/tracks')} disabled={!this.props.spotify_authorized} to={this.props.spotify_authorized ? global.baseURL+"library/tracks" : null}>
|
||||
<Icon name="music" />
|
||||
Tracks
|
||||
</Link>
|
||||
<Link className={this.linkClassName('library/browse')} to={global.baseURL+"library/browse"}>
|
||||
<Icon name="folder" />
|
||||
Browse
|
||||
@ -116,6 +112,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
mopidy_connected: state.mopidy.connected,
|
||||
pusher_connected: state.pusher.connected,
|
||||
spotify_enabled: state.spotify.enabled,
|
||||
spotify_access: state.spotify.access,
|
||||
spotify_connected: state.spotify.connected,
|
||||
spotify_authorized: state.spotify.authorized,
|
||||
dragger: state.ui.dragger
|
||||
|
||||
@ -1034,8 +1034,14 @@ const MopidyMiddleware = (function(){
|
||||
// Fire off our universal track index loader
|
||||
store.dispatch({ type: 'TRACK_LOADED', key: action.data.track.uri, track: action.data.track })
|
||||
|
||||
// Get me some images
|
||||
store.dispatch(mopidyActions.getImages('tracks',[action.data.track.uri]))
|
||||
// We've got Spotify running, and it's a spotify track - go straight to the source!
|
||||
if (helpers.uriSource(action.data.track.uri) == 'spotify' && store.getState().spotify.access != 'none'){
|
||||
store.dispatch(spotifyActions.getTrack(action.data.track.uri))
|
||||
|
||||
// Some other source, rely on Mopidy backends to do their work
|
||||
} else {
|
||||
store.dispatch(mopidyActions.getImages('tracks',[action.data.track.uri]))
|
||||
}
|
||||
}
|
||||
|
||||
next(action)
|
||||
|
||||
@ -126,7 +126,7 @@ function refreshToken( dispatch, getState ){
|
||||
response.source = 'spotify'
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
provider: 'spotify-http-api',
|
||||
access_token_provider: 'http_api',
|
||||
data: response
|
||||
})
|
||||
resolve(response)
|
||||
@ -154,7 +154,7 @@ function refreshToken( dispatch, getState ){
|
||||
token.source = 'mopidy';
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
provider: 'mopidy-spotify',
|
||||
access_token_provider: 'backend',
|
||||
data: token
|
||||
});
|
||||
resolve(token);
|
||||
@ -257,9 +257,17 @@ export function getTrack( uri ){
|
||||
|
||||
sendRequest( dispatch, getState, 'tracks/'+ helpers.getFromUri('trackid', uri) )
|
||||
.then( response => {
|
||||
let track = Object.assign(
|
||||
{},
|
||||
response,
|
||||
{
|
||||
images: response.album.images
|
||||
}
|
||||
)
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TRACK_LOADED',
|
||||
data: response
|
||||
type: 'TRACK_LOADED',
|
||||
key: uri,
|
||||
track: track
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@ -15,13 +15,21 @@ export default function reducer(spotify = {}, action){
|
||||
return Object.assign({}, spotify, { connected: false, connecting: false })
|
||||
|
||||
case 'SPOTIFY_SET_CONFIG':
|
||||
return Object.assign({}, spotify, action.config)
|
||||
var spotify = Object.assign({},spotify,action.config)
|
||||
|
||||
let access = 'none'
|
||||
if (spotify.authentication_provider == 'http_api' && spotify.authorized){
|
||||
access = 'full'
|
||||
} else if (spotify.authentication_provider == 'backend' && spotify.backend_username){
|
||||
access = 'limited'
|
||||
}
|
||||
spotify.access = access
|
||||
return spotify
|
||||
|
||||
case 'PUSHER_SPOTIFY_TOKEN':
|
||||
if( spotify.authorized ) return spotify;
|
||||
return Object.assign({}, spotify, {
|
||||
authorizing: false,
|
||||
authorized: false,
|
||||
authorization: false,
|
||||
access_token: action.data.access_token,
|
||||
token_expiry: action.data.token_expiry
|
||||
@ -29,8 +37,8 @@ export default function reducer(spotify = {}, action){
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_GRANTED':
|
||||
return Object.assign({}, spotify, {
|
||||
access: (spotify.authentication_provider == 'http_api' ? 'full' : 'limited'),
|
||||
authorizing: false,
|
||||
authorized: true,
|
||||
authorization: action.data,
|
||||
access_token: action.data.access_token,
|
||||
refresh_token: action.data.refresh_token,
|
||||
@ -39,9 +47,9 @@ export default function reducer(spotify = {}, action){
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_REVOKED':
|
||||
return Object.assign({}, spotify, {
|
||||
access: (spotify.authentication_provider == 'http_api' ? 'none' : 'limited'),
|
||||
authorizing: false,
|
||||
authorization: false,
|
||||
authorized: false,
|
||||
access_token: false,
|
||||
refresh_token: false,
|
||||
token_expiry: 0,
|
||||
@ -50,8 +58,9 @@ export default function reducer(spotify = {}, action){
|
||||
|
||||
case 'SPOTIFY_IMPORT_AUTHORIZATION':
|
||||
return Object.assign({}, spotify, {
|
||||
authentication_provider: 'http_api',
|
||||
access: 'full',
|
||||
authorizing: false,
|
||||
authorized: true,
|
||||
authorization: action.authorization,
|
||||
access_token: action.authorization.access_token,
|
||||
refresh_token: action.authorization.refresh_token,
|
||||
@ -68,7 +77,7 @@ export default function reducer(spotify = {}, action){
|
||||
refreshing_token: false,
|
||||
access_token: action.data.access_token,
|
||||
token_expiry: action.data.token_expiry,
|
||||
provider: action.provider
|
||||
access_token_provider: action.access_token_provider
|
||||
})
|
||||
|
||||
case 'SPOTIFY_DISCONNECTED':
|
||||
@ -76,26 +85,6 @@ export default function reducer(spotify = {}, action){
|
||||
|
||||
case 'SPOTIFY_ME_LOADED':
|
||||
return Object.assign({}, spotify, { me: action.data })
|
||||
/*
|
||||
case 'SPOTIFY_ARTISTS_LOADED':
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
return Object.assign({}, spotify, {
|
||||
artists: action.data.artists.items,
|
||||
artists_more: action.data.artists.next
|
||||
})
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
return Object.assign({}, spotify, {
|
||||
library_artists: action.data.artists.items,
|
||||
library_artists_more: action.data.artists.next
|
||||
})
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED_MORE':
|
||||
return Object.assign({}, spotify, {
|
||||
library_artists: [ ...spotify.library_artists, ...action.data.artists.items ],
|
||||
library_artists_more: action.data.artists.next
|
||||
})*/
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED':
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
|
||||
@ -39,8 +39,21 @@ class User extends React.Component{
|
||||
}
|
||||
|
||||
isMe(){
|
||||
if( !this.props.spotify_authorized ) return null
|
||||
return helpers.getFromUri('userid',this.props.params.uri) == this.props.me.id
|
||||
let userid = helpers.getFromUri('userid',this.props.params.uri)
|
||||
switch (this.props.spotify_authentication_provider){
|
||||
case 'backend':
|
||||
if (this.props.spotify_authorized && this.props.me){
|
||||
return userid == this.props.me.id
|
||||
}
|
||||
return false
|
||||
break
|
||||
|
||||
case 'http_api':
|
||||
return userid == this.props.spotify_backend_username
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
render(){
|
||||
@ -109,6 +122,8 @@ const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
load_queue: state.ui.load_queue,
|
||||
spotify_authorized: state.spotify.authorized,
|
||||
spotify_authentication_provider: state.spotify.authentication_provider,
|
||||
spotify_backend_username: state.spotify.backend_username,
|
||||
me: state.spotify.me,
|
||||
playlists: state.core.playlists,
|
||||
user: (state.core.users && state.core.users[ownProps.params.uri] !== undefined ? state.core.users[ownProps.params.uri] : false),
|
||||
|
||||
Reference in New Issue
Block a user