Skip to content

Commit

Permalink
Change: show warning readonly message instead of 401
Browse files Browse the repository at this point in the history
Issue #39
  • Loading branch information
satrun77 committed Jul 10, 2016
1 parent b167301 commit 2be7f81
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
53 changes: 42 additions & 11 deletions app/Form/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class Issue extends FormAbstract
*/
protected $tags = null;

/**
* Is issue readonly.
*
* @var bool
*/
protected $readOnly = false;

/**
* @param string $type
*
Expand Down Expand Up @@ -83,6 +90,7 @@ public function setup(array $params)
$this->project = $params['project'];
if (!empty($params['issue'])) {
$this->editingModel($params['issue']);
$this->readOnly = $this->getModel()->hasReadOnlyTag(auth()->user());
}
}

Expand All @@ -91,18 +99,23 @@ public function setup(array $params)
*/
public function actions()
{
$actions = [
'submit' => $this->isEditing() ? 'update_issue' : 'create_issue',
];
$actions = [];

if ($this->isEditing() && auth()->user(Model\Permission::PERM_ISSUE_MODIFY)) {
$actions['delete'] = [
'type' => 'danger_submit',
'label' => trans('tinyissue.delete_something', ['name' => '#' . $this->getModel()->id]),
'class' => 'close-issue',
'name' => 'delete-issue',
'data-message' => trans('tinyissue.delete_issue_confirm'),
// Check if issue is in readonly tag
if (!$this->readOnly) {
$actions = [
'submit' => $this->isEditing() ? 'update_issue' : 'create_issue',
];

if ($this->isEditing() && auth()->user(Model\Permission::PERM_ISSUE_MODIFY)) {
$actions['delete'] = [
'type' => 'danger_submit',
'label' => trans('tinyissue.delete_something', ['name' => '#' . $this->getModel()->id]),
'class' => 'close-issue',
'name' => 'delete-issue',
'data-message' => trans('tinyissue.delete_issue_confirm'),
];
}
}

return $actions;
Expand All @@ -115,7 +128,9 @@ public function fields()
{
$issueModify = \Auth::user()->permission('issue-modify');

$fields = $this->fieldTitle();
$fields = [];
$fields += $this->readOnlyMessage();
$fields += $this->fieldTitle();
$fields += $this->fieldBody();
$fields += $this->fieldTypeTags();

Expand Down Expand Up @@ -160,6 +175,22 @@ protected function issueModifyFields()
return $fields;
}

/**
* Returns message about read only issue.
*
* @return array
*/
protected function readOnlyMessage()
{
return [
'readonly' => [
'type' => 'plaintext',
'label' => ' ',
'value' => '<div class="alert alert-warning">' . trans('tinyissue.readonly_issue_message') . '</div>',
],
];
}

/**
* Returns title field.
*
Expand Down
6 changes: 0 additions & 6 deletions app/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,6 @@ public function permissionInContext(Route $route)
return false;
}

// Check if issue is in readonly tag
$permission = array_get($route->getAction(), 'permission');
if ($issue instanceof Issue && $permission === Permission::PERM_ISSUE_MODIFY) {
return !$issue->hasReadOnlyTag($this);
}

return true;
}

Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/tinyissue.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,5 @@
'attachment_has_been_deleted' => 'The attachment has been deleted.',
'your_created_issues_description' => 'Issues that are created by you',
'issue_created_by_you' => 'Issue Created By You',
'readonly_issue_message' => 'The issue is in read only status.',
];

0 comments on commit 2be7f81

Please sign in to comment.