Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: DataObject scaffolding #20

Merged
merged 66 commits into from
Feb 2, 2017
Merged
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
38535d8
FEATURE: DataObject scaffolding
Dec 12, 2016
ab44175
Fix phpunit.xml syntax
Dec 15, 2016
3b73495
README updates for scaffolding docs
Dec 15, 2016
81e0809
Remove @package declarations
Dec 15, 2016
51c0781
Change $dataObjectName to $dataObjectClass
Dec 15, 2016
a43d143
Type hinting
Dec 15, 2016
eaa4982
Updates to arg creation and resolver logic to all CRUD operations
Dec 15, 2016
68306e7
Add type detection to DataObject getters that are not casted
Dec 15, 2016
2c6379a
Remove @package declaration
Dec 15, 2016
5d061e7
Use new required resolver argument
Dec 15, 2016
ddb0781
More informative exception message
Dec 15, 2016
349cb17
New hasType() method for Manager
Dec 16, 2016
eb1ed99
Provide pagination in scaffolded queries
Dec 18, 2016
e353462
Cast default value for args
Dec 18, 2016
54de8f7
API changes to put queries and mutations at top level, nested query s…
Dec 20, 2016
a47421a
Remove creators, major reorganisation
Dec 20, 2016
327f60c
Update readme with new scaffolding api
Dec 23, 2016
cd2956c
Expose nested queries through public api
Jan 9, 2017
7cec89a
Move operation() method, allow removal by identifier
Jan 9, 2017
8068dd9
Allow allFieldsExcept to take a string
Jan 9, 2017
11c4c44
Move operation() method
Jan 9, 2017
7ccb104
Omit data object class from ancestry
Jan 9, 2017
ee2798a
Allow fieldsExcept or fields to be defined in config, not just fields
Jan 9, 2017
566623c
Bugfix: missing use statement
Jan 9, 2017
beafd24
Bugfix: missing use statement
Jan 9, 2017
11d4ce4
New public api, allowing find and remove by identifier
Jan 9, 2017
253065f
Change conditional block to not return too early
Jan 11, 2017
6e4d784
Change "scaffolds" to "types"
Jan 11, 2017
7a83af4
Use injector get instead of create
Jan 11, 2017
f5b0a38
Remove debug
Jan 11, 2017
b241d0d
Expose args to public api
Jan 11, 2017
fb5cd0d
Add new tests
Jan 11, 2017
554d5e8
format PSR2
Jan 11, 2017
d69a482
rename graphqlscaffolder to schemascaffolder
Jan 11, 2017
c4d9544
namespace updates to README
Jan 11, 2017
5f65e50
README updates
Jan 11, 2017
a823b20
Use non-matching group for type parser
Jan 12, 2017
28d8fd9
More README updates
Jan 12, 2017
a5dbd75
Add can* checks to examples
Jan 12, 2017
5ff2f6b
Add can* checks to CRUD using $context
Jan 12, 2017
69dbe7b
Add input type examples
Jan 12, 2017
5aa0310
replace member use statement
Jan 12, 2017
7daee8e
Add tests for CRUD operations
Jan 13, 2017
f6a3cc3
New addFields API, allow descriptions wildcard in yaml
Jan 14, 2017
46c1967
New argument API. Descriptions/defaults allowed
Jan 17, 2017
36302fe
Update example code
Jan 20, 2017
f49759c
BUGFIX: incorrect array shape for CRUD args
Jan 20, 2017
aeed6c7
BUGFIX: Malformed input type fields
Jan 20, 2017
4716387
PSR2 formatting
Jan 31, 2017
62cdf22
Code formatting for tests
Jan 31, 2017
d018593
Clean up rebasing issues
Jan 31, 2017
1066eb7
docblock revisions
Jan 31, 2017
7672e24
Rename Configurable to ConfigurationApplier
Jan 31, 2017
1977943
More docblock cleanup
Jan 31, 2017
d6eb733
Update example code to use DateTime
Jan 31, 2017
8296a23
Add new fake redirector page so tests pass without CMS
Jan 31, 2017
1456d5b
Build shim classes for Page, SiteTree
Jan 31, 2017
17dc73e
API Separate connection() to get/create
chillu Feb 1, 2017
c08bda7
Use DB transaction for multi delete
chillu Feb 2, 2017
06ff0b2
Fix examples
chillu Feb 2, 2017
198127c
Fix example $db declaration
chillu Feb 2, 2017
641213b
Fix example whitespace
chillu Feb 2, 2017
7047fba
Use DO->update() for create
chillu Feb 1, 2017
3e981b7
Use DataObjectSchema
chillu Feb 2, 2017
7d41007
More example class reference fixes
chillu Feb 2, 2017
fd5d41f
Correct use of currentUser context
chillu Feb 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add can* checks to CRUD using $context
  • Loading branch information
Uncle Cheese committed Jan 31, 2017
commit 5ff2f6ba915599a98dc06565e8e0755f6738326b
2 changes: 1 addition & 1 deletion src/Scaffolding/Scaffolders/CRUD/Create.php
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ public function __construct($dataObjectClass)

// Todo: this is totally half baked
$this->setResolver(function ($object, array $args, $context, $info) {
if (singleton($this->dataObjectClass)->canCreate()) {
if (singleton($this->dataObjectClass)->canCreate($context['currentMember'])) {
$newObject = Injector::inst()->createWithArgs(
$this->dataObjectClass,
$args
2 changes: 1 addition & 1 deletion src/Scaffolding/Scaffolders/CRUD/Delete.php
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ public function __construct($dataObjectClass)
->byIDs($args['IDs']);

foreach ($results as $obj) {
if ($obj->canDelete()) {
if ($obj->canDelete($context['currentMember'])) {
$obj->delete();
} else {
throw new Exception(sprintf(
8 changes: 8 additions & 0 deletions src/Scaffolding/Scaffolders/CRUD/Read.php
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
use SilverStripe\ORM\DataList;
use SilverStripe\GraphQL\Scaffolding\Interfaces\CRUDInterface;
use SilverStripe\GraphQL\Scaffolding\Scaffolders\SchemaScaffolder;
use Exception;

/**
* Scaffolds a generic read operation for DataObjects.
@@ -32,6 +33,13 @@ public function __construct($dataObjectClass)
parent::__construct($operationName, $this->typeName());

$this->setResolver(function ($object, array $args, $context, $info) {
if(!singleton($this->dataObjectClass)->canView($context['currentMember'])) {
throw new Exception(sprintf(
'Cannot create %s',
$this->dataObjectClass
));
}

$list = DataList::create($this->dataObjectClass);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this filter by canView()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but you have to use filterByCallback if you want to be thorough. Otherwise, a simple check against a singleton could work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This callback would need to comply with the OperationResolver interface right? $info would need a ResolveInfo type hint

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm... If you passed it a named class, or an instance, it has to implement OperationResolver, but AFAIK, there's no way to enforce an argument signature on a closure.


return $list;
2 changes: 1 addition & 1 deletion src/Scaffolding/Scaffolders/CRUD/Update.php
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ public function __construct($dataObjectClass)
));
}

if ($obj->canEdit()) {
if ($obj->canEdit($context['currentMember'])) {
$obj->update($args['Input']);
$obj->write();