mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-25 22:50:04 +05:30
Убрал повторный запрос на complete, когда acceptRequired
This commit is contained in:
parent
c7cce17f11
commit
a2293b570e
@ -153,9 +153,6 @@ export function oAuthValidate(oauth) {
|
||||
})
|
||||
.catch((resp = {}) => { // TODO
|
||||
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') {
|
||||
const error = new Error('Permissions accept required');
|
||||
error.acceptRequired = true;
|
||||
dispatch(requirePermissionsAccept());
|
||||
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 function setScopes(scopes) {
|
||||
if (!(scopes instanceof Array)) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
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({
|
||||
error,
|
||||
@ -79,6 +79,12 @@ function oauth(
|
||||
displayCode: payload.displayCode
|
||||
};
|
||||
|
||||
case REQUIRE_PERMISSIONS_ACCEPT:
|
||||
return {
|
||||
...state,
|
||||
acceptRequired: true
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ export default class CompleteState extends AbstractState {
|
||||
const data = {};
|
||||
if (typeof this.isPermissionsAccepted !== 'undefined') {
|
||||
data.accept = this.isPermissionsAccepted;
|
||||
} else if (auth.oauth.acceptRequired) {
|
||||
context.setState(new PermissionsState());
|
||||
return;
|
||||
}
|
||||
context.run('oAuthComplete', data).then((resp) => {
|
||||
// TODO: пусть в стейт попадает флаг или тип авторизации
|
||||
|
@ -112,6 +112,25 @@ describe('CompleteState', () => {
|
||||
|
||||
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', () => {
|
||||
@ -236,7 +255,7 @@ describe('CompleteState', () => {
|
||||
it('should transition to permissions state if rejected with acceptRequired', () => {
|
||||
return testOAuth('reject', {acceptRequired: true}, PermissionsState);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
describe('permissions accept', () => {
|
||||
it('should set flags, when user accepted permissions', () => {
|
||||
@ -301,5 +320,61 @@ describe('CompleteState', () => {
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user