Skip to content

Commit

Permalink
Rename account related mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazoyer committed Jul 16, 2024
1 parent a9e9766 commit 8840235
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class ReadOnlyGraphQLPermissionChecker(GraphQLQueryPermissionCheckerInterface):
allowed_readonly_mutations = ["CoreAccountSelfUpdate"]
allowed_readonly_mutations = ["InfrahubAccountSelfUpdate"]

async def supports(self, account_session: AccountSession) -> bool:
return account_session.authenticated and account_session.read_only
Expand Down
8 changes: 4 additions & 4 deletions backend/infrahub/graphql/mutations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .account import CoreAccountSelfUpdate, CoreAccountTokenCreate, CoreAccountTokenDelete
from .account import InfrahubAccountSelfUpdate, InfrahubAccountTokenCreate, InfrahubAccountTokenDelete
from .artifact_definition import InfrahubArtifactDefinitionMutation
from .attribute import (
AnyAttributeCreate,
Expand Down Expand Up @@ -55,9 +55,9 @@
"BranchUpdate",
"CheckboxAttributeCreate",
"CheckboxAttributeUpdate",
"CoreAccountSelfUpdate",
"CoreAccountTokenCreate",
"CoreAccountTokenDelete",
"InfrahubAccountSelfUpdate",
"InfrahubAccountTokenCreate",
"InfrahubAccountTokenDelete",
"IPPrefixPoolGetResource",
"IPAddressPoolGetResource",
"InfrahubArtifactDefinitionMutation",
Expand Down
28 changes: 14 additions & 14 deletions backend/infrahub/graphql/mutations/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
# pylint: disable=unused-argument


class CoreAccountTokenCreateInput(InputObjectType):
class InfrahubAccountTokenCreateInput(InputObjectType):
name = InputField(String(required=False), description="The name of the token")
expiration = InputField(String(required=False), description="Timestamp when the token expires")


class CoreAccountTokenDeleteInput(InputObjectType):
class InfrahubAccountTokenDeleteInput(InputObjectType):
id = InputField(String(required=True), description="The id of the token to delete")


class CoreAccountUpdateSelfInput(InputObjectType):
class InfrahubAccountUpdateSelfInput(InputObjectType):
password = InputField(String(required=False), description="The new password")
description = InputField(String(required=False), description="The new description")

Expand All @@ -41,7 +41,7 @@ class ValueType(InfrahubObjectType):
value = String(required=True)


class CoreAccountTokenType(InfrahubObjectType):
class InfrahubAccountTokenType(InfrahubObjectType):
id = String(required=True)
token = Field(ValueType)

Expand Down Expand Up @@ -71,9 +71,9 @@ async def mutate(
account = results[0]

mutation_map = {
"CoreAccountTokenCreate": cls.create_token,
"CoreAccountTokenDelete": cls.delete_token,
"CoreAccountSelfUpdate": cls.update_self,
"InfrahubAccountTokenCreate": cls.create_token,
"InfrahubAccountTokenDelete": cls.delete_token,
"InfrahubAccountSelfUpdate": cls.update_self,
}
response = await mutation_map[cls.__name__](db=context.db, account=account, data=data, info=info)

Expand Down Expand Up @@ -137,23 +137,23 @@ async def update_self(
return cls(ok=True) # type: ignore[call-arg]


class CoreAccountTokenCreate(AccountMixin, Mutation):
class InfrahubAccountTokenCreate(AccountMixin, Mutation):
class Arguments:
data = CoreAccountTokenCreateInput(required=True)
data = InfrahubAccountTokenCreateInput(required=True)

ok = Boolean()
object = Field(CoreAccountTokenType)
object = Field(InfrahubAccountTokenType)


class CoreAccountTokenDelete(AccountMixin, Mutation):
class InfrahubAccountTokenDelete(AccountMixin, Mutation):
class Arguments:
data = CoreAccountTokenDeleteInput(required=True)
data = InfrahubAccountTokenDeleteInput(required=True)

ok = Boolean()


class CoreAccountSelfUpdate(AccountMixin, Mutation):
class InfrahubAccountSelfUpdate(AccountMixin, Mutation):
class Arguments:
data = CoreAccountUpdateSelfInput(required=True)
data = InfrahubAccountUpdateSelfInput(required=True)

ok = Boolean()
12 changes: 6 additions & 6 deletions backend/infrahub/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
BranchRebase,
BranchUpdate,
BranchValidate,
CoreAccountSelfUpdate,
CoreAccountTokenCreate,
CoreAccountTokenDelete,
InfrahubAccountSelfUpdate,
InfrahubAccountTokenCreate,
InfrahubAccountTokenDelete,
IPAddressPoolGetResource,
IPPrefixPoolGetResource,
ProcessRepository,
Expand Down Expand Up @@ -109,9 +109,9 @@ class InfrahubBaseQuery(ObjectType):


class InfrahubBaseMutation(ObjectType):
CoreAccountTokenCreate = CoreAccountTokenCreate.Field()
CoreAccountSelfUpdate = CoreAccountSelfUpdate.Field()
CoreAccountTokenDelete = CoreAccountTokenDelete.Field()
InfrahubAccountTokenCreate = InfrahubAccountTokenCreate.Field()
InfrahubAccountSelfUpdate = InfrahubAccountSelfUpdate.Field()
InfrahubAccountTokenDelete = InfrahubAccountTokenDelete.Field()
CoreProposedChangeRunCheck = ProposedChangeRequestRunCheck.Field()

IPPrefixPoolGetResource = IPPrefixPoolGetResource.Field()
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/unit/graphql/test_core_account_self_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def test_everyone_can_update_password(db: InfrahubDatabase, default_branch
new_description = "what a cool description"
query = """
mutation {
CoreAccountSelfUpdate(data: {password: "%s", description: "%s"}) {
InfrahubAccountSelfUpdate(data: {password: "%s", description: "%s"}) {
ok
}
}
Expand All @@ -40,7 +40,7 @@ async def test_everyone_can_update_password(db: InfrahubDatabase, default_branch
)

assert result.errors is None
assert result.data["CoreAccountSelfUpdate"]["ok"] is True
assert result.data["InfrahubAccountSelfUpdate"]["ok"] is True

updated_account = await NodeManager.get_one(db=db, id=first_account.id, branch=default_branch)
assert bcrypt.checkpw(new_password.encode("UTF-8"), updated_account.password.value.encode("UTF-8"))
Expand Down

0 comments on commit 8840235

Please sign in to comment.