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

Add ability edit description on images tickets #136

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion assets/components/tickets/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

case 'ticket/file/upload': $response = $Tickets->fileUpload($_POST, 'Ticket'); break;
case 'ticket/file/delete': $response = $Tickets->fileDelete($_POST['id']); break;
case 'ticket/file/desc': $response = $Tickets->fileDesc($_POST['id'], $_POST['desc']); break;
default:
$message = $_REQUEST['action'] != $action ? 'tickets_err_register_globals' : 'tickets_err_unknown';
$response = $modx->toJSON(array('success' => false, 'message' => $modx->lexicon($message)));
Expand All @@ -82,4 +83,4 @@
}

@session_write_close();
exit($response);
exit($response);
20 changes: 20 additions & 0 deletions core/components/tickets/model/tickets/tickets.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,26 @@ public function fileUpload($data, $class = 'Ticket') {
}


/**
* Edit description in uploaded file
*
* @param $id,$description
*
* @return array|string
*/
public function fileDesc($id,$description) {
if (!$this->authenticated || empty($this->config['allowFiles'])) {
return $this->error('ticket_err_access_denied');
}
/** @var modProcessorResponse $response */
$response = $this->runProcessor('web/file/desc', array('id' => $id, 'description' => $description));
if ($response->isError()) {
return $this->error($response->getMessage());
}

return $this->success();
}

/**
* Delete or restore uploaded file
*
Expand Down
40 changes: 40 additions & 0 deletions core/components/tickets/processors/web/file/desc.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

class TicketFileDescProcessor extends modObjectProcessor {
public $classKey = 'TicketFile';
public $permission = 'ticket_file_upload';


/**
* @return bool|null|string
*/
public function initialize() {
if (!$this->modx->hasPermission($this->permission)) {
return $this->modx->lexicon('access_denied');
}
return true;
}


/**
* @return array|string
*/
public function process() {
$id = $this->getProperty('id');
$description = $this->getProperty('description');
/** @var TicketFile $file */
if (!$file = $this->modx->getObject($this->classKey, $id)) {
return $this->failure($this->modx->lexicon('ticket_err_file_ns'));
}
elseif ($file->createdby != $this->modx->user->id && !$this->modx->user->isMember('Administrator')) {
return $this->failure($this->modx->lexicon('ticket_err_file_owner'));
}
$file->set('description', $description);
$file->save();

return $this->success();
}

}

return 'TicketFileDescProcessor';