зеркало из https://github.com/nextcloud/approval.git
basic mechanism works
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
This commit is contained in:
Родитель
c5706436d0
Коммит
45b0550a85
|
@ -13,7 +13,7 @@ return [
|
|||
'routes' => [
|
||||
['name' => 'config#setConfig', 'url' => '/config', 'verb' => 'PUT'],
|
||||
['name' => 'config#setAdminConfig', 'url' => '/admin-config', 'verb' => 'PUT'],
|
||||
['name' => 'approval#getTags', 'url' => '/{fileId}/tags', 'verb' => 'GET'],
|
||||
['name' => 'approval#isApprovalPending', 'url' => '/{fileId}/is-pending', 'verb' => 'GET'],
|
||||
['name' => 'approval#approve', 'url' => '/{fileId}/approve', 'verb' => 'PUT'],
|
||||
['name' => 'approval#disapprove', 'url' => '/{fileId}/disapprove', 'verb' => 'PUT'],
|
||||
]
|
||||
|
|
|
@ -62,9 +62,9 @@ class ApprovalController extends Controller {
|
|||
* @param int $fileId
|
||||
* @return DataDisplayResponse
|
||||
*/
|
||||
public function getTags(int $fileId): DataResponse {
|
||||
$tags = $this->approvalService->getTags($fileId);
|
||||
return new DataResponse($tags);
|
||||
public function isApprovalPending(int $fileId): DataResponse {
|
||||
$isPending = $this->approvalService->isApprovalPending($fileId);
|
||||
return new DataResponse($isPending);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,6 +13,8 @@ namespace OCA\Approval\Service;
|
|||
|
||||
use OCP\IL10N;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use OCP\SystemTag\ISystemTagManager;
|
||||
use OCP\SystemTag\ISystemTagObjectMapper;
|
||||
|
||||
class ApprovalService {
|
||||
|
||||
|
@ -24,18 +26,23 @@ class ApprovalService {
|
|||
*/
|
||||
public function __construct (string $appName,
|
||||
LoggerInterface $logger,
|
||||
ISystemTagManager $tagManager,
|
||||
ISystemTagObjectMapper $tagObjectMapper,
|
||||
IL10N $l10n) {
|
||||
$this->appName = $appName;
|
||||
$this->l10n = $l10n;
|
||||
$this->logger = $logger;
|
||||
$this->tagManager = $tagManager;
|
||||
$this->tagObjectMapper = $tagObjectMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $fileId
|
||||
* @return array
|
||||
* @return bool
|
||||
*/
|
||||
public function getTags(int $fileId): array {
|
||||
return [];
|
||||
public function isApprovalPending(int $fileId): bool {
|
||||
$tagPending = $this->tagManager->getTag('pending', true, true);
|
||||
return $this->tagObjectMapper->haveTag($fileId, 'files', $tagPending->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,7 +50,13 @@ class ApprovalService {
|
|||
* @return void
|
||||
*/
|
||||
public function approve(int $fileId): void {
|
||||
error_log('Approve '.$fileId);
|
||||
$tagApproved = $this->tagManager->getTag('approved', true, true);
|
||||
$this->tagObjectMapper->assignTags($fileId, 'files', $tagApproved->getId());
|
||||
|
||||
$tagPending = $this->tagManager->getTag('pending', true, true);
|
||||
if ($this->tagObjectMapper->haveTag($fileId, 'files', $tagPending->getId())) {
|
||||
$this->tagObjectMapper->unassignTags($fileId, 'files', $tagPending->getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,6 +64,12 @@ class ApprovalService {
|
|||
* @return void
|
||||
*/
|
||||
public function disapprove(int $fileId): void {
|
||||
error_log('Disapprove '.$fileId);
|
||||
$tagRejected = $this->tagManager->getTag('rejected', true, true);
|
||||
$this->tagObjectMapper->assignTags($fileId, 'files', $tagRejected->getId());
|
||||
|
||||
$tagPending = $this->tagManager->getTag('pending', true, true);
|
||||
if ($this->tagObjectMapper->haveTag($fileId, 'files', $tagPending->getId())) {
|
||||
$this->tagObjectMapper->unassignTags($fileId, 'files', $tagPending->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,34 @@ export const ApprovalInfoView = OCA.Files.DetailFileInfoView.extend(
|
|||
|
||||
initialize(options) {
|
||||
options = options || {}
|
||||
this.render()
|
||||
},
|
||||
|
||||
/**
|
||||
* Renders this details view
|
||||
*/
|
||||
render() {
|
||||
if (this._rendered) {
|
||||
return
|
||||
}
|
||||
// create and mount the component
|
||||
const mountPoint = document.createElement('div')
|
||||
const View = Vue.extend(ApprovalButtons)
|
||||
this._inputView = new View({
|
||||
propsData: { },
|
||||
}).$mount(mountPoint)
|
||||
this.$el.append(this._inputView.$el)
|
||||
|
||||
// listen to approval events
|
||||
this._inputView.$on('yes', () => {
|
||||
this._onApprove()
|
||||
})
|
||||
this._inputView.$on('no', () => {
|
||||
this._onReject()
|
||||
})
|
||||
|
||||
this.hide()
|
||||
this._rendered = true
|
||||
},
|
||||
|
||||
_onApprove() {
|
||||
|
@ -62,39 +90,24 @@ export const ApprovalInfoView = OCA.Files.DetailFileInfoView.extend(
|
|||
},
|
||||
|
||||
setFileInfo(fileInfo) {
|
||||
this.hide()
|
||||
console.debug('setFileInfo')
|
||||
console.debug(fileInfo)
|
||||
// Why is this called twice and fileInfo is not the same on each call?
|
||||
this.fileName = fileInfo.name || fileInfo.attributes?.name || ''
|
||||
this.fileId = fileInfo.id || fileInfo.attributes?.id || 0
|
||||
|
||||
if (!this._rendered) {
|
||||
this.render()
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Renders this details view
|
||||
*/
|
||||
render() {
|
||||
console.debug('RENDER')
|
||||
// create and mount the component
|
||||
const mountPoint = document.createElement('div')
|
||||
const View = Vue.extend(ApprovalButtons)
|
||||
this._inputView = new View({
|
||||
propsData: { },
|
||||
}).$mount(mountPoint)
|
||||
this.$el.append(this._inputView.$el)
|
||||
|
||||
// listen to approval events
|
||||
this._inputView.$on('yes', () => {
|
||||
this._onApprove()
|
||||
const url = generateUrl('/apps/approval/' + this.fileId + '/is-pending')
|
||||
axios.get(url).then((response) => {
|
||||
if (response.data) {
|
||||
this.show()
|
||||
}
|
||||
}).catch((error) => {
|
||||
showError(
|
||||
t('approval', 'Failed to check approval status')
|
||||
+ ': ' + error.response?.request?.responseText
|
||||
)
|
||||
})
|
||||
this._inputView.$on('no', () => {
|
||||
this._onReject()
|
||||
})
|
||||
|
||||
this._rendered = true
|
||||
},
|
||||
|
||||
isVisible() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче