mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
Убрал повторный запрос на complete, когда acceptRequired
This commit is contained in:
@@ -153,9 +153,6 @@ export function oAuthValidate(oauth) {
|
|||||||
})
|
})
|
||||||
.catch((resp = {}) => { // TODO
|
.catch((resp = {}) => { // TODO
|
||||||
handleOauthParamsValidation(resp);
|
handleOauthParamsValidation(resp);
|
||||||
if (resp.statusCode === 401 && resp.error === 'accept_required') {
|
|
||||||
alert('Accept required.');
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -189,6 +186,7 @@ export function oAuthComplete(params = {}) {
|
|||||||
if (resp.statusCode === 401 && resp.error === 'accept_required') {
|
if (resp.statusCode === 401 && resp.error === 'accept_required') {
|
||||||
const error = new Error('Permissions accept required');
|
const error = new Error('Permissions accept required');
|
||||||
error.acceptRequired = true;
|
error.acceptRequired = true;
|
||||||
|
dispatch(requirePermissionsAccept());
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -273,6 +271,13 @@ export function setOAuthCode(oauth) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const REQUIRE_PERMISSIONS_ACCEPT = 'require_permissions_accept';
|
||||||
|
export function requirePermissionsAccept() {
|
||||||
|
return {
|
||||||
|
type: REQUIRE_PERMISSIONS_ACCEPT
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const SET_SCOPES = 'set_scopes';
|
export const SET_SCOPES = 'set_scopes';
|
||||||
export function setScopes(scopes) {
|
export function setScopes(scopes) {
|
||||||
if (!(scopes instanceof Array)) {
|
if (!(scopes instanceof Array)) {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { combineReducers } from 'redux';
|
import { combineReducers } from 'redux';
|
||||||
|
|
||||||
import { ERROR, SET_CLIENT, SET_OAUTH, SET_OAUTH_RESULT, SET_SCOPES, SET_LOADING_STATE } from './actions';
|
import { ERROR, SET_CLIENT, SET_OAUTH, SET_OAUTH_RESULT, SET_SCOPES, SET_LOADING_STATE, REQUIRE_PERMISSIONS_ACCEPT } from './actions';
|
||||||
|
|
||||||
export default combineReducers({
|
export default combineReducers({
|
||||||
error,
|
error,
|
||||||
@@ -79,6 +79,12 @@ function oauth(
|
|||||||
displayCode: payload.displayCode
|
displayCode: payload.displayCode
|
||||||
};
|
};
|
||||||
|
|
||||||
|
case REQUIRE_PERMISSIONS_ACCEPT:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
acceptRequired: true
|
||||||
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,9 @@ export default class CompleteState extends AbstractState {
|
|||||||
const data = {};
|
const data = {};
|
||||||
if (typeof this.isPermissionsAccepted !== 'undefined') {
|
if (typeof this.isPermissionsAccepted !== 'undefined') {
|
||||||
data.accept = this.isPermissionsAccepted;
|
data.accept = this.isPermissionsAccepted;
|
||||||
|
} else if (auth.oauth.acceptRequired) {
|
||||||
|
context.setState(new PermissionsState());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
context.run('oAuthComplete', data).then((resp) => {
|
context.run('oAuthComplete', data).then((resp) => {
|
||||||
// TODO: пусть в стейт попадает флаг или тип авторизации
|
// TODO: пусть в стейт попадает флаг или тип авторизации
|
||||||
|
@@ -112,6 +112,25 @@ describe('CompleteState', () => {
|
|||||||
|
|
||||||
state.enter(context);
|
state.enter(context);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should transition to permissions state if acceptRequired', () => {
|
||||||
|
context.getState.returns({
|
||||||
|
user: {
|
||||||
|
isActive: true,
|
||||||
|
isGuest: false
|
||||||
|
},
|
||||||
|
auth: {
|
||||||
|
oauth: {
|
||||||
|
clientId: 'ely.by',
|
||||||
|
acceptRequired: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expectState(mock, PermissionsState);
|
||||||
|
|
||||||
|
state.enter(context);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('oAuthComplete', () => {
|
describe('oAuthComplete', () => {
|
||||||
@@ -236,7 +255,7 @@ describe('CompleteState', () => {
|
|||||||
it('should transition to permissions state if rejected with acceptRequired', () => {
|
it('should transition to permissions state if rejected with acceptRequired', () => {
|
||||||
return testOAuth('reject', {acceptRequired: true}, PermissionsState);
|
return testOAuth('reject', {acceptRequired: true}, PermissionsState);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
describe('permissions accept', () => {
|
describe('permissions accept', () => {
|
||||||
it('should set flags, when user accepted permissions', () => {
|
it('should set flags, when user accepted permissions', () => {
|
||||||
@@ -301,5 +320,61 @@ describe('CompleteState', () => {
|
|||||||
|
|
||||||
state.enter(context);
|
state.enter(context);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should run oAuthComplete passing accept: true, while acceptRequired: true', () => {
|
||||||
|
// acceptRequired may block user accept/decline actions, so we need
|
||||||
|
// to check that they are accessible
|
||||||
|
const expected = {accept: true};
|
||||||
|
|
||||||
|
state = new CompleteState(expected);
|
||||||
|
context.getState.returns({
|
||||||
|
user: {
|
||||||
|
isActive: true,
|
||||||
|
isGuest: false
|
||||||
|
},
|
||||||
|
auth: {
|
||||||
|
oauth: {
|
||||||
|
clientId: 'ely.by',
|
||||||
|
acceptRequired: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expectRun(
|
||||||
|
mock,
|
||||||
|
'oAuthComplete',
|
||||||
|
sinon.match(expected)
|
||||||
|
).returns({then() {}});
|
||||||
|
|
||||||
|
state.enter(context);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should run oAuthComplete passing accept: false, while acceptRequired: true', () => {
|
||||||
|
// acceptRequired may block user accept/decline actions, so we need
|
||||||
|
// to check that they are accessible
|
||||||
|
const expected = {accept: false};
|
||||||
|
|
||||||
|
state = new CompleteState(expected);
|
||||||
|
context.getState.returns({
|
||||||
|
user: {
|
||||||
|
isActive: true,
|
||||||
|
isGuest: false
|
||||||
|
},
|
||||||
|
auth: {
|
||||||
|
oauth: {
|
||||||
|
clientId: 'ely.by',
|
||||||
|
acceptRequired: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expectRun(
|
||||||
|
mock,
|
||||||
|
'oAuthComplete',
|
||||||
|
sinon.match(expected)
|
||||||
|
).returns({then() {}});
|
||||||
|
|
||||||
|
state.enter(context);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user