Skip to content

Commit

Permalink
Don't modify the field if no canCreate
Browse files Browse the repository at this point in the history
* master:
  NEW Don't modify the field if no canCreate
  • Loading branch information
sheadawson committed Feb 10, 2015
2 parents 140a03b + ea04d75 commit ea3dd47
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions code/extensions/QuickAddNewExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public function useAddNew($class, $sourceCallback, FieldList $fields = null, Req
if(!is_callable($sourceCallback)){
throw new Exception('the useAddNew method must be passed a callable $sourceCallback parameter, ' . gettype($sourceCallback) . ' passed.');
}

// if the user can't create this object type, don't modify the form
if (!singleton($class)->canCreate()) {
return $this->owner;
}

Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
Expand Down Expand Up @@ -132,6 +137,9 @@ public function AddNewFormHTML(){
**/
public function doAddNew($data, $form){
$obj = Object::create($this->addNewClass);
if (!$obj->canCreate()) {
return Security::permissionFailure(Controller::curr(), "You don't have permission to create this object");
}
$form->saveInto($obj);

try {
Expand Down

0 comments on commit ea3dd47

Please sign in to comment.