Rename LocalLogin -> BetaLogin

This commit is contained in:
Christian Cueni 2020-03-09 15:47:50 +01:00
parent 59d5376f60
commit e5b0fe539f
13 changed files with 145 additions and 90 deletions

View File

@ -102,6 +102,34 @@
"deprecationReason": null
},
{
"name": "betaLogin",
"description": null,
"args": [
{
"name": "input",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "BetaLoginInput",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "BetaLoginPayload",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "__debug",
"description": null,
"args": [],
"type": {
@ -294,22 +322,6 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "errors",
"description": null,
"args": [],
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "LoginError",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "clientMutationId",
"description": null,
@ -328,29 +340,6 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "LoginError",
"description": null,
"fields": [
{
"name": "field",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "LoginInput",
@ -382,6 +371,94 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "BetaLoginPayload",
"description": null,
"fields": [
{
"name": "success",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "message",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "clientMutationId",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "BetaLoginInput",
"description": null,
"fields": null,
"inputFields": [
{
"name": "usernameInput",
"description": null,
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "passwordInput",
"description": null,
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "clientMutationId",
"description": null,
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "DjangoDebug",
@ -1490,5 +1567,4 @@
}
]
}
}

View File

@ -32,14 +32,14 @@ import '@iam4x/cypress-graphql-mock';
Cypress.Commands.add('apolloLogin', (username, password) => {
const payload = {
'operationName': 'LocalLogin',
'operationName': 'BetaLogin',
'variables': {
'input': {
'usernameInput': username,
'passwordInput': password
}
},
'query': 'mutation LocalLogin($input: LocalLoginInput!) {\n localLogin(input: $input) {\n success\n errors {\n field\n __typename\n }\n __typename\n }\n}\n'
'query': 'mutation BetaLogin($input: BetaLoginInput!) {\n betaLogin(input: $input) {\n success\n errors {\n field\n __typename\n }\n __typename\n }\n}\n'
};
cy.request({

View File

@ -0,0 +1,6 @@
mutation BetaLogin($input: BetaLoginInput!) {
betaLogin(input: $input) {
success
message
}
}

View File

@ -2,8 +2,5 @@ mutation Login($input: LoginInput!) {
login(input: $input) {
success
message
errors {
field
}
}
}

View File

@ -1,9 +0,0 @@
mutation LocalLogin($input: LocalLoginInput!) {
localLogin(input: $input) {
success
message
errors {
field
}
}
}

View File

@ -71,7 +71,7 @@
</template>
<script>
import LOGIN_LOCAL_MUTATION from '@/graphql/gql/mutations/loginLocal.gql';
import BETA_LOGIN_MUTATION from '@/graphql/gql/mutations/betaLogin.gql';
export default {
components: {},
@ -84,7 +84,7 @@ export default {
if (result) {
this.$apollo.mutate({
client: 'publicClient',
mutation: LOGIN_LOCAL_MUTATION,
mutation: BETA_LOGIN_MUTATION,
variables: {
input: {
usernameInput: this.email,
@ -95,12 +95,12 @@ export default {
store,
{
data: {
localLogin
betaLogin
}
}
) {
try {
if (localLogin.success) {
if (betaLogin.success) {
const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/'
that.$router.push(redirectUrl);
}

View File

@ -28,7 +28,7 @@ import surveyPage from '@/pages/survey'
import styleGuidePage from '@/pages/styleguide'
import moduleRoom from '@/pages/moduleRoom'
import login from '@/pages/login'
import loginLocal from '@/pages/login-local'
import betaLogin from '@/pages/beta-login'
import hello from '@/pages/hello'
import registration from '@/pages/registration'
import waitForClass from '@/pages/waitForClass'
@ -68,7 +68,7 @@ const routes = [
{
path: '/beta-login',
name: 'betaLogin',
component: loginLocal,
component: betaLogin,
meta: {
layout: 'public',
public: true

View File

@ -376,7 +376,7 @@ TASKBASE_SUPERPASSWORD = os.environ.get("TASKBASE_SUPERPASSWORD")
TASKBASE_BASEURL = os.environ.get("TASKBASE_BASEURL")
ALLOW_LOCAL_LOGIN = True
ALLOW_BETA_LOGIN = True
# HEP
HEP_ADMIN_USER = "myskillbox"

View File

@ -20,7 +20,7 @@ class ApiAccessTestCase(TestCase):
self.assertEqual(response.url, '/login?next=/api/graphql/')
def test_graphqlEndpoint_shouldBeAccessibleWithLogin(self):
user = UserFactory(username='admin')
UserFactory(username='admin')
c = Client()
c.login(username='admin', password='test')
@ -31,14 +31,11 @@ class ApiAccessTestCase(TestCase):
def test_publicGraphqlEndpoint_shouldBeAccessibleWithoutLogin(self):
query= json.dumps({
'operationName': 'LocalLogin',
'operationName': 'BetaLogin',
'query': '''
mutation LocalLogin($input: LocalLoginInput!){
localLogin(input: $input) {
mutation BetaLogin($input: BetaLoginInput!){
betaLogin(input: $input) {
success
errors {
field
}
}
}
''',

View File

@ -17,22 +17,17 @@ from core.hep_client import HepClient, HepClientUnauthorizedException, HepClient
from users.user_signup_login_handler import handle_user_and_verify_products, UNKNOWN_ERROR, EMAIL_NOT_VERIFIED
class LoginError(graphene.ObjectType):
field = graphene.String()
class LocalLogin(relay.ClientIDMutation):
class BetaLogin(relay.ClientIDMutation):
class Input:
username_input = graphene.String()
password_input = graphene.String()
success = graphene.Boolean()
message = graphene.String()
errors = graphene.List(LoginError) # todo: change for consistency
@classmethod
def mutate_and_get_payload(cls, root, info, **kwargs):
if settings.ALLOW_LOCAL_LOGIN:
if settings.ALLOW_BETA_LOGIN:
password = kwargs.get('password_input')
username = kwargs.get('username_input')
user = authenticate(username=username, password=password)
@ -40,7 +35,7 @@ class LocalLogin(relay.ClientIDMutation):
raise Exception('invalid_credentials')
login(info.context, user)
return cls(success=True, errors=[], message='')
return cls(success=True, message='')
raise Exception('not_implemented')
@ -51,7 +46,6 @@ class Login(relay.ClientIDMutation):
success = graphene.Boolean()
message = graphene.String()
errors = graphene.List(LoginError) # todo: change for consistency
@classmethod
def mutate_and_get_payload(cls, root, info, **kwargs):
@ -75,18 +69,18 @@ class Login(relay.ClientIDMutation):
if status_msg:
return cls.return_login_message(status_msg)
return cls(success=True, errors=[], message='success')
return cls(success=True, message='success')
@classmethod
def return_login_message(cls, message):
if message == EMAIL_NOT_VERIFIED or message == UNKNOWN_ERROR or message == 'invalid_credentials':
raise Exception(message)
return cls(success=True, errors=[], message=message)
return cls(success=True, message=message)
class UserMutations:
login = Login.Field()
local_login = LocalLogin.Field()
beta_login = BetaLogin.Field()

View File

@ -16,7 +16,7 @@ from core.factories import UserFactory
from users.models import Role
class LocalLoginTests(TestCase):
class BetaLoginTests(TestCase):
def setUp(self):
self.user = UserFactory(username='aschi@iterativ.ch', email='aschi@iterativ.ch')
self.teacher_role = Role.objects.create(key=Role.objects.TEACHER_KEY, name="Teacher Role")
@ -31,12 +31,9 @@ class LocalLoginTests(TestCase):
def make_login_mutation(self, username, password):
mutation = '''
mutation LocalLogin($input: LocalLoginInput!){
localLogin(input: $input) {
mutation BetaLogin($input: BetaLoginInput!){
betaLogin(input: $input) {
success
errors {
field
}
}
}
'''
@ -54,7 +51,7 @@ class LocalLoginTests(TestCase):
self.user.save()
result = self.make_login_mutation(self.user.email, password)
self.assertTrue(result.get('data').get('localLogin').get('success'))
self.assertTrue(result.get('data').get('betaLogin').get('success'))
self.assertTrue(self.user.is_authenticated)
def test_user_cannot_login_with_invalid_password(self):

View File

@ -49,9 +49,6 @@ class LoginTests(TestCase):
login(input: $input) {
success
message
errors {
field
}
}
}
'''