Skip to content

Commit

Permalink
Update permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-dna committed Jul 26, 2018
1 parent 59e51f6 commit 96c94ac
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/models/DecisionTreeAnswer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,30 @@ public function getCMSFields()
return $fields;
}

/**
* Permissions
*/
public function canCreate($member = null)
{
return singleton('ElementDecisionTree')->canCreate($member);
}

public function canView($member = null)
{
return singleton('ElementDecisionTree')->canCreate($member);
}

public function canEdit($member = null)
{
return singleton('ElementDecisionTree')->canCreate($member);
}

/**
* Can only delete an answer that doesn't have a dependant question
*/
public function canDelete($member = null)
{
$canDelete = parent::canDelete($member);
$canDelete = singleton('ElementDecisionTree')->canDelete($member);
return ($canDelete && !$this->ResultingStep()->exists());
}

Expand Down
20 changes: 19 additions & 1 deletion src/models/DecisionTreeStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,30 @@ public function onBeforeWrite()
parent::onBeforeWrite();
}

/**
* Permissions
*/
public function canCreate($member = null)
{
return singleton('ElementDecisionTree')->canCreate($member);
}

public function canView($member = null)
{
return singleton('ElementDecisionTree')->canCreate($member);
}

public function canEdit($member = null)
{
return singleton('ElementDecisionTree')->canCreate($member);
}

/**
* Prevent deleting Step with answers that have dependant questions
*/
public function candelete($member = null)
{
$canDelete = parent::canDelete($member);
$canDelete = singleton('ElementDecisionTree')->canDelete($member);

foreach($this->Answers() as $answer) {
if (!$answer->canDelete()) {
Expand Down

0 comments on commit 96c94ac

Please sign in to comment.