Skip to content

Commit

Permalink
Merge branch 'next' into feature/FOUR-13174
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanpro committed Jan 19, 2024
2 parents f8ec392 + c90f921 commit bdd4fb7
Show file tree
Hide file tree
Showing 61 changed files with 791 additions and 224 deletions.
26 changes: 25 additions & 1 deletion ProcessMaker/Filters/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Illuminate\Support\Arr;
use ProcessMaker\Models\ProcessRequestToken;
use ProcessMaker\Models\User;
use ProcessMaker\Query\BaseField;
use ProcessMaker\Query\Expression;

class Filter
{
Expand All @@ -17,6 +19,8 @@ class Filter

const TYPE_PROCESS = 'Process';

const TYPE_RELATIONSHIP = 'Relationship';

public string|null $subjectValue;

public string $subjectType;
Expand Down Expand Up @@ -63,6 +67,8 @@ private function apply($query)
$this->valueAliasAdapter($valueAliasMethod, $query);
} elseif ($this->subjectType === self::TYPE_PROCESS) {
$this->filterByProcessId($query);
} elseif ($this->subjectType === self::TYPE_RELATIONSHIP) {
$this->filterByRelationship($query);
} else {
$this->applyQueryBuilderMethod($query);
}
Expand Down Expand Up @@ -103,7 +109,7 @@ private function operator()
if ($this->operator === 'regex') {
$this->operator = 'REGEXP';
}

return $this->operator;
}

Expand Down Expand Up @@ -145,9 +151,18 @@ private function subject()
return 'process_id';
}

if ($this->subjectType === self::TYPE_RELATIONSHIP) {
return $this->relationshipSubjectTypeParts()[1];
}

return $this->subjectValue;
}

private function relationshipSubjectTypeParts()
{
return explode('.', $this->subjectValue);
}

private function value()
{
if ($this->operator === 'contains') {
Expand Down Expand Up @@ -212,6 +227,7 @@ private function convertUserIdsToUsernames($values)
{
return array_map(function ($value) {
$username = User::find($value)?->username;

return isset($username) ? $username : $value;
}, $values);
}
Expand All @@ -227,4 +243,12 @@ private function filterByProcessId(Builder $query)
$this->applyQueryBuilderMethod($query);
}
}

private function filterByRelationship(Builder $query)
{
$relationshipName = $this->relationshipSubjectTypeParts()[0];
$query->whereHas($relationshipName, function ($rel) {
$this->applyQueryBuilderMethod($rel);
});
}
}
16 changes: 9 additions & 7 deletions ProcessMaker/Filters/SaveSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class SaveSession
{
/**
* Retrieve cached data; this is preserved for a week.
* @param Array $json
* @return Array
* @param array $json
* @return array
*/
private static function get($key, $json)
{
return Cache::remember($key, now()->addWeek(), function () use($json) {
return Cache::remember($key, now()->addWeek(), function () use ($json) {
return $json;
});
}
Expand All @@ -26,24 +26,25 @@ private static function get($key, $json)
*/
private static function getKey($user, $name)
{
return str_replace("-", "_", "user-{$user->id}-{$user->uuid}-{$name}");
return str_replace('-', '_', "user-{$user->id}-{$user->uuid}-{$name}");
}

/**
* Get filter configuration.
* @param String $name
* @param string $name
* @param User $user
* @return type
*/
public static function getConfigFilter(String $name, Object $user)
{
$key = self::getKey($user, $name);

return self::get($key, []);
}

/**
* Store filter configuration.
* @param String $name
* @param string $name
* @param User $user
* @param array $array
* @return type
Expand All @@ -52,6 +53,7 @@ public static function setConfigFilter(String $name, Object $user, array $array)
{
$key = self::getKey($user, $name);
Cache::pull($key);

return self::get($key, $array);
}
}
}
2 changes: 1 addition & 1 deletion ProcessMaker/Http/Controllers/Api/BookmarkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function store(Request $request, Process $process)
try {
$bookmark->updateOrCreate([
'process_id' => $process->id,
'user_id' => Auth::user()->id
'user_id' => Auth::user()->id,
]);
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 400);
Expand Down
61 changes: 36 additions & 25 deletions ProcessMaker/Http/Controllers/Api/ProcessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ProcessController extends Controller
'bpmn',
'svg',
];

public $doNotSanitizeMustache = [
'case_title',
];
Expand Down Expand Up @@ -122,6 +123,9 @@ public function index(Request $request)
$processes->processCategory($category);
}

// Filter by category status
$processes->categoryStatus($request->input('cat_status', null));

if (!empty($pmql)) {
try {
$processes->pmql($pmql);
Expand Down Expand Up @@ -262,10 +266,10 @@ public function startEvents(Request $request, Process $process)
$startEvents = [];
$currentUser = Auth::user();
foreach ($process->start_events as $event) {
if (count($event["eventDefinitions"]) === 0) {
if (array_key_exists("config", $event)) {
$webEntry = json_decode($event["config"])->web_entry;
$event["webEntry"] = $webEntry;
if (count($event['eventDefinitions']) === 0) {
if (array_key_exists('config', $event)) {
$webEntry = json_decode($event['config'])->web_entry;
$event['webEntry'] = $webEntry;
}
if (
$this->checkUserCanStartProcess($event, $currentUser->id, $process, $request) ||
Expand All @@ -275,6 +279,7 @@ public function startEvents(Request $request, Process $process)
}
}
}

return new ApiCollection($startEvents);
}

Expand Down Expand Up @@ -466,7 +471,7 @@ public function update(Request $request, Process $process)
}
}

$this->saveImagesIntoMedia($request, $process);
$this->saveImagesIntoMedia($request, $process);
// Catch errors to send more specific status
try {
$process->saveOrFail();
Expand Down Expand Up @@ -1497,6 +1502,7 @@ protected function getRequestFilterBy(Request $request, array $searchableColumns

return $where;
}

/**
* check if currentUser can start the request
*
Expand All @@ -1510,23 +1516,24 @@ protected function getRequestFilterBy(Request $request, array $searchableColumns
protected function checkUserCanStartProcess($event, $currentUser, $process, $request)
{
$response = false;
if (array_key_exists("assignment", $event)) {
switch ($event["assignment"]) {
case "user":
if (array_key_exists("assignedUsers", $event)) {
$response = $currentUser === (int)$event["assignedUsers"];
if (array_key_exists('assignment', $event)) {
switch ($event['assignment']) {
case 'user':
if (array_key_exists('assignedUsers', $event)) {
$response = $currentUser === (int) $event['assignedUsers'];
}
break;
case "group":
if (array_key_exists("assignedGroups", $event)) {
$response = $this->checkUsersGroup((int)$event["assignedGroups"], $request);
case 'group':
if (array_key_exists('assignedGroups', $event)) {
$response = $this->checkUsersGroup((int) $event['assignedGroups'], $request);
}
break;
case "process_manager":
break;
case 'process_manager':
$response = $currentUser === $process->manager_id;
break;
break;
}
}

return $response;
}

Expand All @@ -1543,24 +1550,24 @@ protected function checkUsersGroup(int $groupId, Request $request)
$currentUser = Auth::user()->id;
$group = Group::find($groupId);
$response = false;
if (isset($group)){
if (isset($group)) {
try {
$responseUsers = (new GroupController(new Group()))->users($group, $request);
$users = $responseUsers->all();

foreach ($users as $user) {
if($user->resource->member_id === $currentUser) {
if ($user->resource->member_id === $currentUser) {
$response = true;
}
}
} catch (\Exception $error) {
return ['error' => $error->getMessage()];
}

try {
$responseGroups = (new GroupController(new Group()))->groups($group, $request);
$groups = $responseGroups->all();

foreach ($groups as $group) {
if ($this->checkUsersGroup($group->resource->member_id, $request)) {
$response = true;
Expand All @@ -1570,6 +1577,7 @@ protected function checkUsersGroup(int $groupId, Request $request)
return ['error' => $error->getMessage()];
}
}

return $response;
}

Expand Down Expand Up @@ -1697,7 +1705,7 @@ public function duplicate(Process $process, Request $request)
}

public function saveImagesIntoMedia(Request $request, Process $process)
{
{
// Saving Carousel Images into Media table related to process_id
if (is_array($request->imagesCarousel) && !empty($request->imagesCarousel)) {
foreach ($request->imagesCarousel as $image) {
Expand All @@ -1706,19 +1714,22 @@ public function saveImagesIntoMedia(Request $request, Process $process)
->where('uuid', $image['uuid'])->exists()) {
$process->addMediaFromBase64($image['url'])->toMediaCollection('images_carousel');
}
}
}
}
}
}

public function getMediaImages(Request $request, Process $process) {
public function getMediaImages(Request $request, Process $process)
{
$media = Process::with(['media'])
->where('id', $process->id)
->get();

return new ProcessCollection($media);
}

public function deleteMediaImages(Request $request, Process $process) {
public function deleteMediaImages(Request $request, Process $process)
{
$process = Process::find($process->id);

// Get UUID image in media table
Expand Down
1 change: 1 addition & 0 deletions ProcessMaker/Http/Controllers/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ private function validateCellPhoneNumber(User $user, $number)
],
], 422);
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ class TwoFactorAuthController extends Controller
private $twoFactorAuthentication;

const TFA_ERROR = '2fa-error';

const TFA_MESSAGE = '2fa-message';

const TFA_AUTH_APP = '2fa-auth-app';

const TFA_VALIDATED = '2fa-validated';

public function __construct()
Expand Down Expand Up @@ -173,6 +176,7 @@ private function testEmailServer()
'message' => __('Unable to send email. Please check your email server settings.'),
], 500);
}

return true;
}

Expand Down Expand Up @@ -206,6 +210,7 @@ private function testSmsServer()
'message' => __('Unable to send SMS. Please check your cell number and SMS server settings.'),
], 500);
}

return true;
}
}
4 changes: 2 additions & 2 deletions ProcessMaker/Http/Controllers/RequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function index($type = null)
['type', 'title', 'currentUser']
));
}
$userFilter = SaveSession::getConfigFilter("requestFilter", Auth::user());

$userFilter = SaveSession::getConfigFilter('requestFilter', Auth::user());

return view('requests.index', compact(
['type', 'title', 'currentUser', 'userFilter']
Expand Down
4 changes: 2 additions & 2 deletions ProcessMaker/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function index()
if (isset($_SERVER['HTTP_USER_AGENT']) && MobileHelper::isMobile($_SERVER['HTTP_USER_AGENT'])) {
return view('tasks.mobile', compact('title'));
}
$userFilter = SaveSession::getConfigFilter("taskFilter", Auth::user());

$userFilter = SaveSession::getConfigFilter('taskFilter', Auth::user());

return view('tasks.index', compact('title', 'userFilter'));
}
Expand Down
1 change: 1 addition & 0 deletions ProcessMaker/Http/Middleware/SanitizeInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SanitizeInput extends TransformsRequest
public $except = [
//
];

public $allowExpressions = [];

/**
Expand Down
9 changes: 5 additions & 4 deletions ProcessMaker/Http/Middleware/SessionControlBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class SessionControlBlock
{
const IP_RESTRICTION_KEY = 'session-control.ip_restriction';

const DEVICE_RESTRICTION_KEY = 'session-control.device_restriction';

/**
Expand Down Expand Up @@ -42,10 +43,10 @@ public function handle(Request $request, Closure $next): Response

private function getUser(Request $request): ?User
{
return User::with(['sessions' => function($query) {
$query->where('is_active', true);
}])
->whereHas('sessions', function(Builder $query) {
return User::with(['sessions' => function ($query) {
$query->where('is_active', true);
}])
->whereHas('sessions', function (Builder $query) {
$query->where('is_active', true);
})->where('username', $request->input('username'))
->first();
Expand Down
Loading

0 comments on commit bdd4fb7

Please sign in to comment.