Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release-2024-fall' into feature/…
Browse files Browse the repository at this point in the history
…FOUR-18130-fall
  • Loading branch information
pmPaulis committed Oct 15, 2024
2 parents f007b85 + a41eb3e commit e57e35c
Show file tree
Hide file tree
Showing 45 changed files with 1,065 additions and 1,661 deletions.
16 changes: 16 additions & 0 deletions ProcessMaker/Constants/CaseStatusConstants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace ProcessMaker\Constants;

class CaseStatusConstants
{
public const ACTIVE = 'ACTIVE';

public const IN_PROGRESS = 'IN_PROGRESS';

public const COMPLETED = 'COMPLETED';

public const ERROR = 'ERROR';

public const CANCELED = 'CANCELED';
}
1 change: 1 addition & 0 deletions ProcessMaker/Enums/ExporterMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum ExporterMap
\ProcessMaker\Models\ScreenTemplates::class,
\ProcessMaker\ImportExport\Exporters\ScreenTemplatesExporter::class,
],
'screen_translation' => [\ProcessMaker\Package\Translations\Models\Translatable::class, \ProcessMaker\Package\Translations\ImportExport\TranslatableExporter::class],
];

public static function getModelClass(string $type): ?string
Expand Down
10 changes: 10 additions & 0 deletions ProcessMaker/Exception/MissingScreenPageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace ProcessMaker\Exception;

use Exception;

class MissingScreenPageException extends Exception
{
protected $message = 'The specified screen page does not exist in the configuration. Please try saving the screen or check the configuration.';
}
11 changes: 0 additions & 11 deletions ProcessMaker/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ public function edit(User $user)
$permissionNames = $user->permissions()->pluck('name')->toArray();
$permissionGroups = $all_permissions->sortBy('title')->groupBy('group')->sortKeys();

$langs = [];
foreach (scandir(app()->langPath()) as $file) {
preg_match('/([a-z]{2})\\.json/', $file, $matches);
if (!empty($matches)) {
$langs[] = $matches[1];
}
}
// Our form controls need attribute:value pairs sot we convert the langs array to and associative one
$availableLangs = array_combine($langs, $langs);

$currentUser = $user;
$states = JsonData::states();
$countries = JsonData::countries();
Expand Down Expand Up @@ -96,7 +86,6 @@ function ($result, $item) {
'timezones',
'countries',
'datetimeFormats',
'availableLangs',
'status',
'enabled2FA',
'global2FAEnabled',
Expand Down
12 changes: 11 additions & 1 deletion ProcessMaker/Http/Controllers/Api/ProcessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ public function update(Request $request, Process $process)
if (!$request->has('name')) {
unset($rules['name']);
}
if ($request->has('default_for_anon_webentry')) {
$rules = ['language_code' => 'required_if:default_for_anon_webentry,true'];
}
$request->validate($rules);
$original = $process->getOriginal();

Expand Down Expand Up @@ -505,6 +508,13 @@ public function update(Request $request, Process $process)
$this->saveTaskNotifications($process, $request);
}

// Save default language for anon web entry...
if ($request->has(['default_for_anon_webentry', 'language_code'])) {
$process->default_anon_web_language = $request->input('default_for_anon_webentry')
? $request->input('language_code')
: null;
}

$isTemplate = Process::select('is_template')->where('id', $process->id)->value('is_template');
if ($isTemplate) {
try {
Expand Down Expand Up @@ -1683,7 +1693,7 @@ protected function getRequestInclude(Request $request)
*/
protected function getRequestFields(Request $request)
{
$fields = $request->input('fields', 'id,name,description');
$fields = $request->input('fields', 'id,name,description,default_anon_web_language');

return $fields ? explode(',', $fields) : [];
}
Expand Down
6 changes: 5 additions & 1 deletion ProcessMaker/Http/Controllers/Api/ScreenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ public function preview(Request $request)
* Translates the controls inside a screen
*
* @param Screen $screen, the id of the screen that will be translated
* @param String $language, language to translate. If the translation does not exist
* @param string $language, language to translate. If the translation does not exist
* english is applied by default
*
* @return ResponseFactory|Response
Expand Down Expand Up @@ -675,12 +675,16 @@ public function preview(Request $request)
public function translate(Request $request, Screen $screen, $language)
{
$draft = $screen->versions()->draft()->first();
if (!$draft) {
$draft = $screen;
}
$processTranslation = new ProcessTranslation(null);
$transConfig = $processTranslation->translateScreen(
$draft,
$request->input('screenConfig'),
$request->input('inputData'),
$language);

return $transConfig;
}

Expand Down
17 changes: 17 additions & 0 deletions ProcessMaker/Http/Controllers/Api/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,23 @@ public function update(Request $request, ProcessRequestToken $task)
return abort(422);
}
}

public function updateReassign(Request $request)
{
$userToAssign = $request->input('user_id');
if (is_array($request->process_request_token)) {
foreach ($request->process_request_token as $value) {
$processRequestToken = ProcessRequestToken::find($value);
//Claim the task for the current user.
$processRequestToken->reassign($request->user()->id, $request->user());

//Reassign to the user.
$processRequestToken->reassign($userToAssign, $request->user());
$taskRefreshed = $processRequestToken->refresh();
CaseUpdate::dispatch($processRequestToken->processRequest, $taskRefreshed);
}
}
}

private function handleQueryException($e)
{
Expand Down
65 changes: 65 additions & 0 deletions ProcessMaker/Http/Controllers/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use ProcessMaker\Events\UserCreated;
use ProcessMaker\Events\UserDeleted;
Expand Down Expand Up @@ -140,6 +141,70 @@ public function index(Request $request)
return new ApiCollection($response);
}

/**
* Display a listing of users and their task counts.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*
* @OA\Get(
* path="/users_count_tasks",
* summary="Returns all users and their total tasks",
* operationId="getUsersTaskCount",
* tags={"Users"},
* @OA\Parameter(
* name="filter",
* in="query",
* description="Filter results by string. Searches First Name, Last Name, Email, or Username.",
* @OA\Schema(type="string"),
* ),
* @OA\Response(
* response=200,
* description="List of users with task counts",
* @OA\JsonContent(
* type="object",
* @OA\Property(
* property="data",
* type="array",
* @OA\Items(ref="#/components/schemas/users"),
* ),
* @OA\Property(
* property="meta",
* type="object",
* ref="#/components/schemas/metadata",
* ),
* ),
* ),
* )
*/
public function getUsersTaskCount(Request $request)
{
$query = User::nonSystem();

$filter = $request->input('filter', '');
if (!empty($filter)) {
$filter = '%' . $filter . '%';
$query->where(function ($query) use ($filter) {
$query->where('username', 'like', $filter)
->orWhere('firstname', 'like', $filter)
->orWhere('lastname', 'like', $filter);
});
}

$query->where('status', 'ACTIVE');

$query->select('*', DB::Raw("(SELECT COUNT(id) FROM process_request_tokens WHERE user_id=users.id AND status='ACTIVE' AND element_type='task') AS count"));
$query->groupBy('users.id');

$response = $query->orderBy(
$request->input('order_by', 'username'),
$request->input('order_direction', 'ASC')
)
->paginate(50);

return new ApiCollection($response);
}

/**
* Store a newly created resource in storage.
*
Expand Down
9 changes: 1 addition & 8 deletions ProcessMaker/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ public function edit()
['value' => 'INACTIVE', 'text' => __('Inactive')],
];

$langs = ['en'];
if (app()->getProvider(\ProcessMaker\Package\Translations\PackageServiceProvider::class)) {
$langs = i18nHelper::availableLangs();
}
// Our form controls need attribute:value pairs sot we convert the langs array to and associative one
$availableLangs = array_combine($langs, $langs);

$timezones = array_reduce(JsonData::timezones(),
function ($result, $item) {
$result[$item] = $item;
Expand All @@ -59,7 +52,7 @@ function ($result, $item) {
$addons = $this->getPluginAddons('edit', []);

return view('profile.edit',
compact('currentUser', 'states', 'timezones', 'countries', 'datetimeFormats', 'availableLangs',
compact('currentUser', 'states', 'timezones', 'countries', 'datetimeFormats',
'status', 'enabled2FA', 'global2FAEnabled', 'is2FAEnabledForGroup', 'addons'));
}

Expand Down
14 changes: 11 additions & 3 deletions ProcessMaker/ImportExport/Exporters/ExporterBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use ProcessMaker\ImportExport\Manifest;
use ProcessMaker\ImportExport\Options;
use ProcessMaker\ImportExport\Psudomodels\Psudomodel;
use ProcessMaker\Models\Screen;
use ProcessMaker\ProcessTranslations\Languages;
use ProcessMaker\Traits\HasVersioning;

Expand Down Expand Up @@ -354,10 +355,17 @@ public function getDescription()
public function getExtraAttributes($model): array
{
$translatedLanguages = [];
if ($model->translations) {
foreach ($model->translations as $key => $value) {
$translatedLanguages[$key] = Languages::ALL[$key];

if ($model::class === Screen::class) {
// Get the translations for the screen
foreach ($this->getDependents('screen-translations') as $dependent) {
if ($dependent->type === 'screen-translations') {
$translatedLanguages[$dependent->meta['language_code']] = Languages::ALL[$dependent->meta['language_code']];
}
}
} elseif ($model->translations && $model->language_code) {
// Get the translations for the model translatable
$translatedLanguages[$model->language_code] = Languages::ALL[$model->language_code];
}

return [
Expand Down
48 changes: 21 additions & 27 deletions ProcessMaker/ProcessTranslations/ProcessTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
namespace ProcessMaker\ProcessTranslations;

use Carbon\Carbon;
use DOMXPath;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Collection as SupportCollection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Cache;
use ProcessMaker\Assets\ScreensInProcess;
use ProcessMaker\Assets\ScreensInScreen;
use ProcessMaker\ImportExport\Utils;
use ProcessMaker\Models\MustacheExpressionEvaluator;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessTranslationToken;
use ProcessMaker\Models\Screen;
use ProcessMaker\Package\Translations\Models\Translatable;

class ProcessTranslation
{
Expand Down Expand Up @@ -153,17 +148,17 @@ private function getStringsInScreen($screen)

$result = [];
$imgPattern = '/<img[^>]+>/';
foreach($strings as $string) {
foreach ($strings as $string) {
if ($this->includeImages && preg_match($imgPattern, $string)) {
$result[] = preg_replace_callback($imgPattern,
function ($matches) {
$hash = sha1($matches[0]);
Cache::put('img.'.$hash, $matches[0], now()->addMinutes(15));
Cache::put('img.' . $hash, $matches[0], now()->addMinutes(15));

return '<img src="' . $hash . '"/>';
},
$string);
}
else {
} else {
$result[] = $string ?? '';
}
}
Expand Down Expand Up @@ -244,7 +239,6 @@ public function applyTranslations($screen)
return;
}
$config = $screen['config'];
$translations = $screen['translations'];
$targetLanguage = '';

if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
Expand All @@ -257,17 +251,7 @@ public function applyTranslations($screen)
$targetLanguage = Auth::user()->language;
}

if (!$translations) {
return $config;
}

if (array_key_exists($targetLanguage, $translations)) {
foreach ($translations[$targetLanguage]['strings'] as $translation) {
$this->applyTranslationsToScreen($translation['key'], $translation['string'], $config);
}
}

return $config;
return $this->searchTranslations($screen['screen_id'], $config, $targetLanguage);
}

public function translateScreen($screen, $screenConfig, $data, $language)
Expand All @@ -280,16 +264,26 @@ public function translateScreen($screen, $screenConfig, $data, $language)
$configEvaluated = $mustacheEngine->render(json_encode($screenConfig), $data);

$config = json_decode($configEvaluated, true);
$translations = $screen['translations'];
$targetLanguage = $language;

return $this->searchTranslations($screen['id'], $config, $language);
}

public function searchTranslations($screenId, $config, $language)
{
$translations = null;
if (class_exists(Translatable::class)) {
$translations = Translatable::where('translatable_id', $screenId)
->where('translatable_type', Screen::class)
->where('language_code', $language)->first();
}

if (!$translations) {
return $config;
}

if (array_key_exists($targetLanguage, $translations)) {
foreach ($translations[$targetLanguage]['strings'] as $translation) {
$this->applyTranslationsToScreen($translation['key'], $translation['string'], $config);
foreach ($translations->translations as $key => $translation) {
if ($translation) {
$this->applyTranslationsToScreen($key, $translation, $config);
}
}

Expand Down
Loading

0 comments on commit e57e35c

Please sign in to comment.