-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add super rough list of changes UI/API
- Loading branch information
Showing
9 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from uuid import UUID | ||
|
||
import graphene | ||
import graphene_django_optimizer as gql_optimizer | ||
from graphql.error import GraphQLError | ||
|
||
from atlas.models import Change | ||
from atlas.schema import ChangeNode | ||
|
||
|
||
class Query(object): | ||
changes = graphene.List( | ||
ChangeNode, | ||
id=graphene.UUID(), | ||
object_type=graphene.String(), | ||
object_id=graphene.UUID(), | ||
offset=graphene.Int(), | ||
limit=graphene.Int(), | ||
) | ||
|
||
def resolve_changes( | ||
self, | ||
info, | ||
id: str = None, | ||
object_type: str = None, | ||
object_id: UUID = None, | ||
offset: int = 0, | ||
limit: int = 1000, | ||
**kwargs | ||
): | ||
assert limit <= 1000 | ||
assert offset >= 0 | ||
|
||
current_user = info.context.user | ||
if not current_user.is_authenticated: | ||
raise GraphQLError("You must be authenticated") | ||
|
||
if not current_user.is_superuser: | ||
raise GraphQLError("You must be superuser") | ||
|
||
qs = Change.objects.all().distinct() | ||
|
||
if id: | ||
qs = qs.filter(id=id) | ||
|
||
if object_type: | ||
qs = qs.filter(object_type=object_type) | ||
|
||
if object_id: | ||
qs = qs.filter(object_id=object_id) | ||
|
||
qs = qs.order_by("-timestamp") | ||
|
||
return list(gql_optimizer.query(qs, info)[offset:limit]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from atlas.models import Change | ||
|
||
|
||
def test_changes(gql_client, default_user, default_office): | ||
change = Change.objects.create( | ||
object_type="user", | ||
object_id=default_user.id, | ||
changes={"name": "Joe Dirt"}, | ||
user=default_user, | ||
) | ||
|
||
executed = gql_client.execute("""{changes {id}}""", user=default_user) | ||
assert executed["data"]["changes"] == [{"id": str(change.id)}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import graphene_django_optimizer as gql_optimizer | ||
|
||
from atlas.models import Change | ||
|
||
|
||
class ChangeNode(gql_optimizer.OptimizedDjangoObjectType): | ||
class Meta: | ||
model = Change | ||
name = "Change" | ||
fields = ( | ||
"id", | ||
"object_type", | ||
"object_id", | ||
"user", | ||
"changes", | ||
"timestamp", | ||
"version", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from "react"; | ||
import { Link } from "react-router"; | ||
import { Flex, Box } from "@rebass/grid/emotion"; | ||
import { Query } from "react-apollo"; | ||
|
||
import Card from "../components/Card"; | ||
import PageLoader from "../components/PageLoader"; | ||
import { LIST_CHANGES_QUERY } from "../queries"; | ||
|
||
export default () => ( | ||
<section> | ||
<Card> | ||
<h1>Changes</h1> | ||
</Card> | ||
<Card withPadding> | ||
<Query | ||
query={LIST_CHANGES_QUERY} | ||
variables={{ | ||
limit: 1000 | ||
}} | ||
> | ||
{({ loading, error, data }) => { | ||
if (error) throw error; | ||
if (loading) return <PageLoader />; | ||
const { changes } = data; | ||
return changes.map(c => ( | ||
<div style={{ marginBottom: "0.5rem" }}> | ||
<Flex> | ||
<Box flex="1"> | ||
<Link to={`/admin/changes/${c.id}`}> | ||
{c.objectType} {c.objectId} | ||
</Link> | ||
<div> | ||
<small>{c.changes}</small> | ||
</div> | ||
</Box> | ||
<Box style={{ width: 50 }}>{c.version}</Box> | ||
<Box style={{ width: 200 }}>{c.user && c.user.email}</Box> | ||
<Box style={{ textAlign: "right" }}>{c.timestamp}</Box> | ||
</Flex> | ||
</div> | ||
)); | ||
}} | ||
</Query> | ||
</Card> | ||
</section> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters