Skip to content

Commit

Permalink
feat(Core): add query to return password requirements (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheikhgwane authored Oct 1, 2024
1 parent 542f652 commit 8b8d5d9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
snake_case_fallback_resolvers,
)

from hexa.core.schema import config_bindables, config_type_defs
from hexa.countries.schema import countries_bindables, countries_type_defs
from hexa.databases.schema import databases_bindables, databases_types_def
from hexa.datasets.schema import datasets_bindables, datasets_type_defs
Expand Down Expand Up @@ -59,6 +60,7 @@ def parse_uuid_value(value):
workspaces_type_def,
databases_types_def,
files_type_def,
config_type_defs,
datasets_type_defs,
],
[
Expand All @@ -76,6 +78,7 @@ def parse_uuid_value(value):
*databases_bindables,
*files_bindables,
*datasets_bindables,
*config_bindables,
snake_case_fallback_resolvers,
],
directives=identity_directives,
Expand Down
13 changes: 13 additions & 0 deletions hexa/core/graphql/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type Config {
"""
List of requirements for the password.
"""
passwordRequirements: [String!]
}

extend type Query {
"""
Retrieves the configuration of the system.
"""
config: Config!
}
28 changes: 28 additions & 0 deletions hexa/core/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pathlib

from ariadne import (
ObjectType,
QueryType,
load_schema_from_path,
)
from django.contrib.auth.password_validation import password_validators_help_texts

config_type_defs = load_schema_from_path(
f"{pathlib.Path(__file__).parent.resolve()}/graphql/schema.graphql"
)

config_object = ObjectType("Config")
config_query = QueryType()


@config_query.field("config")
def resolve_config(_, info):
return config_object


@config_object.field("passwordRequirements")
def resolve_config_password_requirements(_, info):
return password_validators_help_texts()


config_bindables = [config_query, config_object]
18 changes: 18 additions & 0 deletions hexa/core/tests/test_schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.contrib.auth.password_validation import password_validators_help_texts

from hexa.core.test import GraphQLTestCase
from hexa.plugins.connector_airflow.models import (
DAG,
Expand Down Expand Up @@ -46,3 +48,19 @@ def setUpTestData(cls):
cls.DAG = DAG.objects.create(template=template, dag_id="Test DAG 1 ")

DAGPermission.objects.create(dag=cls.DAG, team=cls.TEAM_1)

def test_get_password_requirements_config(self):
response = self.run_query(
"""
query {
config {
passwordRequirements
}
}
"""
)

self.assertEqual(
response["data"]["config"]["passwordRequirements"],
password_validators_help_texts(),
)

0 comments on commit 8b8d5d9

Please sign in to comment.