Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bc6c05a
Add workflowengine
MorrisJobke Jul 26, 2016
6eabcf1
create an operation based on the correct model
MorrisJobke Jul 26, 2016
497954c
Move template to workflowengine app
MorrisJobke Jul 26, 2016
80eeedc
Add app to provisioning output
nickvergessen Jul 26, 2016
b2e4a8c
fix unit tests
MorrisJobke Jul 26, 2016
01ec62e
fix enabled apps tests
MorrisJobke Jul 27, 2016
155e4ce
Generate the checks list in JS
nickvergessen Jul 26, 2016
6a21289
Remove php side of check registration
nickvergessen Jul 27, 2016
34f46c8
Fix morris comments
nickvergessen Jul 27, 2016
0ebc3bb
Fix default value of operator
nickvergessen Jul 27, 2016
ec8ec17
Allow to reuse the template
nickvergessen Jul 27, 2016
2a4a127
Allow DI of the workflow manager by the OCP interface
nickvergessen Jul 27, 2016
8e0e85c
Fix loading icon for workflowengine
MorrisJobke Jul 27, 2016
f814ef6
Add L10N support
nickvergessen Jul 27, 2016
c425a67
Add workflowengine to check-code call
MorrisJobke Aug 3, 2016
df3ca56
Make sure each plugin is only added once
nickvergessen Jul 27, 2016
7b73c0f
Add the systemtag js files
nickvergessen Jul 27, 2016
7b87935
Add system tag check
nickvergessen Jul 27, 2016
627f243
Add file size as check
nickvergessen Jul 27, 2016
d146df5
Add file mime type
nickvergessen Jul 28, 2016
45c74cd
User agent check
nickvergessen Jul 28, 2016
01d269b
Add Request URL
nickvergessen Jul 28, 2016
af3eaa8
Add remote address
nickvergessen Jul 28, 2016
f1869cd
Add request time
nickvergessen Jul 28, 2016
e978c39
add a UI to render proper time picker
MorrisJobke Jul 29, 2016
66fd216
Load the timezones via select2
nickvergessen Aug 1, 2016
cc719c9
Translate the errors
nickvergessen Aug 1, 2016
c12c083
Tags need to be loaded before
nickvergessen Aug 1, 2016
7d71535
Allow to define the operation
nickvergessen Aug 2, 2016
065763f
No multi support, less magic
nickvergessen Aug 2, 2016
8d23405
Ooops
nickvergessen Aug 2, 2016
fc7bd03
Add access control and automated tagging as shipped
nickvergessen Aug 3, 2016
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
Prev Previous commit
Next Next commit
Translate the errors
  • Loading branch information
nickvergessen committed Aug 3, 2016
commit cc719c9bb7ee8e2298dcb22c95c594586c8bf13d
15 changes: 13 additions & 2 deletions apps/workflowengine/lib/Check/AbstractStringCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,24 @@


use OCP\Files\Storage\IStorage;
use OCP\IL10N;
use OCP\WorkflowEngine\ICheck;

abstract class AbstractStringCheck implements ICheck {

/** @var array[] Nested array: [Pattern => [ActualValue => Regex Result]] */
protected $matches;

/** @var IL10N */
protected $l;

/**
* @param IL10N $l
*/
public function __construct(IL10N $l) {
$this->l = $l;
}

/**
* @param IStorage $storage
* @param string $path
Expand Down Expand Up @@ -81,12 +92,12 @@ protected function executeStringCheck($operator, $checkValue, $actualValue) {
*/
public function validateCheck($operator, $value) {
if (!in_array($operator, ['is', '!is', 'matches', '!matches'])) {
throw new \UnexpectedValueException('Invalid operator', 1);
throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
}

if (in_array($operator, ['matches', '!matches']) &&
@preg_match($value, null) === false) {
throw new \UnexpectedValueException('Invalid regex', 2);
throw new \UnexpectedValueException($this->l->t('The given regular expression is invalid'), 2);
}
}

Expand Down
5 changes: 4 additions & 1 deletion apps/workflowengine/lib/Check/FileMimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


use OCP\Files\IMimeTypeDetector;
use OCP\IL10N;
use OCP\IRequest;

class FileMimeType extends AbstractStringCheck {
Expand All @@ -37,10 +38,12 @@ class FileMimeType extends AbstractStringCheck {
protected $mimeTypeDetector;

/**
* @param IL10N $l
* @param IRequest $request
* @param IMimeTypeDetector $mimeTypeDetector
*/
public function __construct(IRequest $request, IMimeTypeDetector $mimeTypeDetector) {
public function __construct(IL10N $l, IRequest $request, IMimeTypeDetector $mimeTypeDetector) {
parent::__construct($l);
$this->request = $request;
$this->mimeTypeDetector = $mimeTypeDetector;
}
Expand Down
12 changes: 9 additions & 3 deletions apps/workflowengine/lib/Check/FileSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


use OCP\Files\Storage\IStorage;
use OCP\IL10N;
use OCP\IRequest;
use OCP\Util;
use OCP\WorkflowEngine\ICheck;
Expand All @@ -32,13 +33,18 @@ class FileSize implements ICheck {
/** @var int */
protected $size;

/** @var IL10N */
protected $l;

/** @var IRequest */
protected $request;

/**
* @param IL10N $l
* @param IRequest $request
*/
public function __construct(IRequest $request) {
public function __construct(IL10N $l, IRequest $request) {
$this->l = $l;
$this->request = $request;
}

Expand Down Expand Up @@ -80,11 +86,11 @@ public function executeCheck($operator, $value) {
*/
public function validateCheck($operator, $value) {
if (!in_array($operator, ['less', '!less', 'greater', '!greater'])) {
throw new \UnexpectedValueException('Invalid operator', 1);
throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
}

if (!preg_match('/^[0-9]+[ ]?[kmgt]?b$/i', $value)) {
throw new \UnexpectedValueException('Invalid file size', 2);
throw new \UnexpectedValueException($this->l->t('The given file size is invalid'), 2);
}
}

Expand Down
14 changes: 10 additions & 4 deletions apps/workflowengine/lib/Check/FileSystemTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use OCP\Files\Cache\ICache;
use OCP\Files\Storage\IStorage;
use OCP\IL10N;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\SystemTag\TagNotFoundException;
Expand All @@ -37,6 +38,9 @@ class FileSystemTags implements ICheck {
/** @var array */
protected $fileSystemTags;

/** @var IL10N */
protected $l;

/** @var ISystemTagManager */
protected $systemTagManager;

Expand All @@ -50,10 +54,12 @@ class FileSystemTags implements ICheck {
protected $path;

/**
* @param IL10N $l
* @param ISystemTagManager $systemTagManager
* @param ISystemTagObjectMapper $systemTagObjectMapper
*/
public function __construct(ISystemTagManager $systemTagManager, ISystemTagObjectMapper $systemTagObjectMapper) {
public function __construct(IL10N $l, ISystemTagManager $systemTagManager, ISystemTagObjectMapper $systemTagObjectMapper) {
$this->l = $l;
$this->systemTagManager = $systemTagManager;
$this->systemTagObjectMapper = $systemTagObjectMapper;
}
Expand Down Expand Up @@ -84,15 +90,15 @@ public function executeCheck($operator, $value) {
*/
public function validateCheck($operator, $value) {
if (!in_array($operator, ['is', '!is'])) {
throw new \UnexpectedValueException('Invalid operator', 1);
throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
}

try {
$this->systemTagManager->getTagsByIds($value);
} catch (TagNotFoundException $e) {
throw new \UnexpectedValueException('Tag does not exist', 2);
throw new \UnexpectedValueException($this->l->t('The given tag id is invalid'), 2);
} catch (\InvalidArgumentException $e) {
throw new \UnexpectedValueException('Tag does not exist', 3);
throw new \UnexpectedValueException($this->l->t('The given tag id is invalid'), 3);
}
}

Expand Down
20 changes: 13 additions & 7 deletions apps/workflowengine/lib/Check/RequestRemoteAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,24 @@


use OCP\Files\Storage\IStorage;
use OCP\IL10N;
use OCP\IRequest;
use OCP\WorkflowEngine\ICheck;

class RequestRemoteAddress implements ICheck {

/** @var IL10N */
protected $l;

/** @var IRequest */
protected $request;

/**
* @param IL10N $l
* @param IRequest $request
*/
public function __construct(IRequest $request) {
public function __construct(IL10N $l, IRequest $request) {
$this->l = $l;
$this->request = $request;
}

Expand Down Expand Up @@ -73,27 +79,27 @@ public function executeCheck($operator, $value) {
*/
public function validateCheck($operator, $value) {
if (!in_array($operator, ['matchesIPv4', '!matchesIPv4', 'matchesIPv6', '!matchesIPv6'])) {
throw new \UnexpectedValueException('Invalid operator', 1);
throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
}

$decodedValue = explode('/', $value);
if (sizeof($decodedValue) !== 2) {
throw new \UnexpectedValueException('Invalid IP range', 2);
throw new \UnexpectedValueException($this->l->t('The given IP range is invalid'), 2);
}

if (in_array($operator, ['matchesIPv4', '!matchesIPv4'])) {
if (!filter_var($decodedValue[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
throw new \UnexpectedValueException('Invalid IPv4 range', 3);
throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv4'), 3);
}
if ($decodedValue[1] > 32 || $decodedValue[1] <= 0) {
throw new \UnexpectedValueException('Invalid IPv4 range', 4);
throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv4'), 4);
}
} else {
if (!filter_var($decodedValue[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
throw new \UnexpectedValueException('Invalid IPv6 range', 3);
throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv6'), 3);
}
if ($decodedValue[1] > 128 || $decodedValue[1] <= 0) {
throw new \UnexpectedValueException('Invalid IPv6 range', 4);
throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv6'), 4);
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions apps/workflowengine/lib/Check/RequestTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\Storage\IStorage;
use OCP\IL10N;
use OCP\WorkflowEngine\ICheck;

class RequestTime implements ICheck {
Expand All @@ -34,13 +35,17 @@ class RequestTime implements ICheck {
/** @var bool[] */
protected $cachedResults;

/** @var IL10N */
protected $l;

/** @var ITimeFactory */
protected $timeFactory;

/**
* @param ITimeFactory $timeFactory
*/
public function __construct(ITimeFactory $timeFactory) {
public function __construct(IL10N $l, ITimeFactory $timeFactory) {
$this->l = $l;
$this->timeFactory = $timeFactory;
}

Expand Down Expand Up @@ -101,24 +106,24 @@ protected function getTimestamp($currentTimestamp, $value) {
*/
public function validateCheck($operator, $value) {
if (!in_array($operator, ['in', '!in'])) {
throw new \UnexpectedValueException('Invalid operator', 1);
throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
}

$regexValue = '\"' . self::REGEX_TIME . ' ' . self::REGEX_TIMEZONE . '\"';
$result = preg_match('/^\[' . $regexValue . ',' . $regexValue . '\]$/', $value, $matches);
if (!$result) {
throw new \UnexpectedValueException('Invalid time limits', 2);
throw new \UnexpectedValueException($this->l->t('The given time span is invalid'), 2);
}

$values = json_decode($value, true);
$time1 = \DateTime::createFromFormat('H:i e', $values[0]);
if ($time1 === false) {
throw new \UnexpectedValueException('Invalid start time given', 3);
throw new \UnexpectedValueException($this->l->t('The given start time is invalid'), 3);
}

$time2 = \DateTime::createFromFormat('H:i e', $values[1]);
if ($time2 === false) {
throw new \UnexpectedValueException('Invalid end time given', 3);
throw new \UnexpectedValueException($this->l->t('The given end time is invalid'), 4);
}
}
}
5 changes: 4 additions & 1 deletion apps/workflowengine/lib/Check/RequestURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace OCA\WorkflowEngine\Check;


use OCP\IL10N;
use OCP\IRequest;

class RequestURL extends AbstractStringCheck {
Expand All @@ -33,9 +34,11 @@ class RequestURL extends AbstractStringCheck {
protected $request;

/**
* @param IL10N $l
* @param IRequest $request
*/
public function __construct(IRequest $request) {
public function __construct(IL10N $l, IRequest $request) {
parent::__construct($l);
$this->request = $request;
}

Expand Down
5 changes: 4 additions & 1 deletion apps/workflowengine/lib/Check/RequestUserAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace OCA\WorkflowEngine\Check;


use OCP\IL10N;
use OCP\IRequest;

class RequestUserAgent extends AbstractStringCheck {
Expand All @@ -30,9 +31,11 @@ class RequestUserAgent extends AbstractStringCheck {
protected $request;

/**
* @param IL10N $l
* @param IRequest $request
*/
public function __construct(IRequest $request) {
public function __construct(IL10N $l, IRequest $request) {
parent::__construct($l);
$this->request = $request;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/workflowengine/lib/Check/UserGroupMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public function executeCheck($operator, $value) {
*/
public function validateCheck($operator, $value) {
if (!in_array($operator, ['is', '!is'])) {
throw new \UnexpectedValueException($this->l->t('Operator %s is invalid', $operator), 1);
throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
}

if (!$this->groupManager->groupExists($value)) {
throw new \UnexpectedValueException($this->l->t('Group %s does not exist', $value), 2);
throw new \UnexpectedValueException($this->l->t('The given group does not exist'), 2);
}
}

Expand Down
Loading