Skip to content

Commit e57e35c

Browse files
committed
Merge remote-tracking branch 'origin/release-2024-fall' into feature/FOUR-18130-fall
2 parents f007b85 + a41eb3e commit e57e35c

45 files changed

Lines changed: 1065 additions & 1661 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace ProcessMaker\Constants;
4+
5+
class CaseStatusConstants
6+
{
7+
public const ACTIVE = 'ACTIVE';
8+
9+
public const IN_PROGRESS = 'IN_PROGRESS';
10+
11+
public const COMPLETED = 'COMPLETED';
12+
13+
public const ERROR = 'ERROR';
14+
15+
public const CANCELED = 'CANCELED';
16+
}

ProcessMaker/Enums/ExporterMap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum ExporterMap
2121
\ProcessMaker\Models\ScreenTemplates::class,
2222
\ProcessMaker\ImportExport\Exporters\ScreenTemplatesExporter::class,
2323
],
24+
'screen_translation' => [\ProcessMaker\Package\Translations\Models\Translatable::class, \ProcessMaker\Package\Translations\ImportExport\TranslatableExporter::class],
2425
];
2526

2627
public static function getModelClass(string $type): ?string
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace ProcessMaker\Exception;
4+
5+
use Exception;
6+
7+
class MissingScreenPageException extends Exception
8+
{
9+
protected $message = 'The specified screen page does not exist in the configuration. Please try saving the screen or check the configuration.';
10+
}

ProcessMaker/Http/Controllers/Admin/UserController.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ public function edit(User $user)
4040
$permissionNames = $user->permissions()->pluck('name')->toArray();
4141
$permissionGroups = $all_permissions->sortBy('title')->groupBy('group')->sortKeys();
4242

43-
$langs = [];
44-
foreach (scandir(app()->langPath()) as $file) {
45-
preg_match('/([a-z]{2})\\.json/', $file, $matches);
46-
if (!empty($matches)) {
47-
$langs[] = $matches[1];
48-
}
49-
}
50-
// Our form controls need attribute:value pairs sot we convert the langs array to and associative one
51-
$availableLangs = array_combine($langs, $langs);
52-
5343
$currentUser = $user;
5444
$states = JsonData::states();
5545
$countries = JsonData::countries();
@@ -96,7 +86,6 @@ function ($result, $item) {
9686
'timezones',
9787
'countries',
9888
'datetimeFormats',
99-
'availableLangs',
10089
'status',
10190
'enabled2FA',
10291
'global2FAEnabled',

ProcessMaker/Http/Controllers/Api/ProcessController.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ public function update(Request $request, Process $process)
457457
if (!$request->has('name')) {
458458
unset($rules['name']);
459459
}
460+
if ($request->has('default_for_anon_webentry')) {
461+
$rules = ['language_code' => 'required_if:default_for_anon_webentry,true'];
462+
}
460463
$request->validate($rules);
461464
$original = $process->getOriginal();
462465

@@ -505,6 +508,13 @@ public function update(Request $request, Process $process)
505508
$this->saveTaskNotifications($process, $request);
506509
}
507510

511+
// Save default language for anon web entry...
512+
if ($request->has(['default_for_anon_webentry', 'language_code'])) {
513+
$process->default_anon_web_language = $request->input('default_for_anon_webentry')
514+
? $request->input('language_code')
515+
: null;
516+
}
517+
508518
$isTemplate = Process::select('is_template')->where('id', $process->id)->value('is_template');
509519
if ($isTemplate) {
510520
try {
@@ -1683,7 +1693,7 @@ protected function getRequestInclude(Request $request)
16831693
*/
16841694
protected function getRequestFields(Request $request)
16851695
{
1686-
$fields = $request->input('fields', 'id,name,description');
1696+
$fields = $request->input('fields', 'id,name,description,default_anon_web_language');
16871697

16881698
return $fields ? explode(',', $fields) : [];
16891699
}

ProcessMaker/Http/Controllers/Api/ScreenController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ public function preview(Request $request)
637637
* Translates the controls inside a screen
638638
*
639639
* @param Screen $screen, the id of the screen that will be translated
640-
* @param String $language, language to translate. If the translation does not exist
640+
* @param string $language, language to translate. If the translation does not exist
641641
* english is applied by default
642642
*
643643
* @return ResponseFactory|Response
@@ -675,12 +675,16 @@ public function preview(Request $request)
675675
public function translate(Request $request, Screen $screen, $language)
676676
{
677677
$draft = $screen->versions()->draft()->first();
678+
if (!$draft) {
679+
$draft = $screen;
680+
}
678681
$processTranslation = new ProcessTranslation(null);
679682
$transConfig = $processTranslation->translateScreen(
680683
$draft,
681684
$request->input('screenConfig'),
682685
$request->input('inputData'),
683686
$language);
687+
684688
return $transConfig;
685689
}
686690

ProcessMaker/Http/Controllers/Api/TaskController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,23 @@ public function update(Request $request, ProcessRequestToken $task)
329329
return abort(422);
330330
}
331331
}
332+
333+
public function updateReassign(Request $request)
334+
{
335+
$userToAssign = $request->input('user_id');
336+
if (is_array($request->process_request_token)) {
337+
foreach ($request->process_request_token as $value) {
338+
$processRequestToken = ProcessRequestToken::find($value);
339+
//Claim the task for the current user.
340+
$processRequestToken->reassign($request->user()->id, $request->user());
341+
342+
//Reassign to the user.
343+
$processRequestToken->reassign($userToAssign, $request->user());
344+
$taskRefreshed = $processRequestToken->refresh();
345+
CaseUpdate::dispatch($processRequestToken->processRequest, $taskRefreshed);
346+
}
347+
}
348+
}
332349

333350
private function handleQueryException($e)
334351
{

ProcessMaker/Http/Controllers/Api/UserController.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Auth\Access\AuthorizationException;
77
use Illuminate\Http\Request;
88
use Illuminate\Support\Facades\Auth;
9+
use Illuminate\Support\Facades\DB;
910
use Illuminate\Support\Facades\Hash;
1011
use ProcessMaker\Events\UserCreated;
1112
use ProcessMaker\Events\UserDeleted;
@@ -140,6 +141,70 @@ public function index(Request $request)
140141
return new ApiCollection($response);
141142
}
142143

144+
/**
145+
* Display a listing of users and their task counts.
146+
*
147+
* @param \Illuminate\Http\Request $request
148+
* @return \Illuminate\Http\Response
149+
*
150+
* @OA\Get(
151+
* path="/users_count_tasks",
152+
* summary="Returns all users and their total tasks",
153+
* operationId="getUsersTaskCount",
154+
* tags={"Users"},
155+
* @OA\Parameter(
156+
* name="filter",
157+
* in="query",
158+
* description="Filter results by string. Searches First Name, Last Name, Email, or Username.",
159+
* @OA\Schema(type="string"),
160+
* ),
161+
* @OA\Response(
162+
* response=200,
163+
* description="List of users with task counts",
164+
* @OA\JsonContent(
165+
* type="object",
166+
* @OA\Property(
167+
* property="data",
168+
* type="array",
169+
* @OA\Items(ref="#/components/schemas/users"),
170+
* ),
171+
* @OA\Property(
172+
* property="meta",
173+
* type="object",
174+
* ref="#/components/schemas/metadata",
175+
* ),
176+
* ),
177+
* ),
178+
* )
179+
*/
180+
public function getUsersTaskCount(Request $request)
181+
{
182+
$query = User::nonSystem();
183+
184+
$filter = $request->input('filter', '');
185+
if (!empty($filter)) {
186+
$filter = '%' . $filter . '%';
187+
$query->where(function ($query) use ($filter) {
188+
$query->where('username', 'like', $filter)
189+
->orWhere('firstname', 'like', $filter)
190+
->orWhere('lastname', 'like', $filter);
191+
});
192+
}
193+
194+
$query->where('status', 'ACTIVE');
195+
196+
$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"));
197+
$query->groupBy('users.id');
198+
199+
$response = $query->orderBy(
200+
$request->input('order_by', 'username'),
201+
$request->input('order_direction', 'ASC')
202+
)
203+
->paginate(50);
204+
205+
return new ApiCollection($response);
206+
}
207+
143208
/**
144209
* Store a newly created resource in storage.
145210
*

ProcessMaker/Http/Controllers/ProfileController.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ public function edit()
2727
['value' => 'INACTIVE', 'text' => __('Inactive')],
2828
];
2929

30-
$langs = ['en'];
31-
if (app()->getProvider(\ProcessMaker\Package\Translations\PackageServiceProvider::class)) {
32-
$langs = i18nHelper::availableLangs();
33-
}
34-
// Our form controls need attribute:value pairs sot we convert the langs array to and associative one
35-
$availableLangs = array_combine($langs, $langs);
36-
3730
$timezones = array_reduce(JsonData::timezones(),
3831
function ($result, $item) {
3932
$result[$item] = $item;
@@ -59,7 +52,7 @@ function ($result, $item) {
5952
$addons = $this->getPluginAddons('edit', []);
6053

6154
return view('profile.edit',
62-
compact('currentUser', 'states', 'timezones', 'countries', 'datetimeFormats', 'availableLangs',
55+
compact('currentUser', 'states', 'timezones', 'countries', 'datetimeFormats',
6356
'status', 'enabled2FA', 'global2FAEnabled', 'is2FAEnabledForGroup', 'addons'));
6457
}
6558

ProcessMaker/ImportExport/Exporters/ExporterBase.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use ProcessMaker\ImportExport\Manifest;
1616
use ProcessMaker\ImportExport\Options;
1717
use ProcessMaker\ImportExport\Psudomodels\Psudomodel;
18+
use ProcessMaker\Models\Screen;
1819
use ProcessMaker\ProcessTranslations\Languages;
1920
use ProcessMaker\Traits\HasVersioning;
2021

@@ -354,10 +355,17 @@ public function getDescription()
354355
public function getExtraAttributes($model): array
355356
{
356357
$translatedLanguages = [];
357-
if ($model->translations) {
358-
foreach ($model->translations as $key => $value) {
359-
$translatedLanguages[$key] = Languages::ALL[$key];
358+
359+
if ($model::class === Screen::class) {
360+
// Get the translations for the screen
361+
foreach ($this->getDependents('screen-translations') as $dependent) {
362+
if ($dependent->type === 'screen-translations') {
363+
$translatedLanguages[$dependent->meta['language_code']] = Languages::ALL[$dependent->meta['language_code']];
364+
}
360365
}
366+
} elseif ($model->translations && $model->language_code) {
367+
// Get the translations for the model translatable
368+
$translatedLanguages[$model->language_code] = Languages::ALL[$model->language_code];
361369
}
362370

363371
return [

0 commit comments

Comments
 (0)