Skip to content

Commit b296afe

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 14b8b3b + 8aa298f commit b296afe

27 files changed

+1647
-1060
lines changed

app/Http/Controllers/SettingsController.php

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
use App\Http\Requests\ImageUploadRequest;
88
use App\Http\Requests\SettingsSamlRequest;
99
use App\Http\Requests\SetupUserRequest;
10+
use App\Http\Requests\StoreLdapSettings;
11+
use App\Http\Requests\StoreLocalizationSettings;
12+
use App\Http\Requests\StoreNotificationSettings;
13+
use App\Http\Requests\StoreLabelSettings;
14+
use App\Http\Requests\StoreSecuritySettings;
1015
use App\Models\CustomField;
1116
use App\Models\Group;
1217
use App\Models\Setting;
@@ -273,20 +278,6 @@ public function index() : View
273278
return view('settings/index', compact('settings'));
274279
}
275280

276-
/**
277-
* Return the admin settings page.
278-
*
279-
* @author [A. Gianotto] [<[email protected]>]
280-
*
281-
* @since [v1.0]
282-
*/
283-
public function getEdit() : View
284-
285-
{
286-
$setting = Setting::getSettings();
287-
288-
return view('settings/general', compact('setting'));
289-
}
290281

291282
/**
292283
* Return a form to allow a super admin to update settings.
@@ -486,7 +477,7 @@ public function getSecurity() : View
486477
*
487478
* @since [v1.0]
488479
*/
489-
public function postSecurity(Request $request) : RedirectResponse
480+
public function postSecurity(StoreSecuritySettings $request) : RedirectResponse
490481
{
491482
$this->validate($request, [
492483
'pwd_secure_complexity' => 'array',
@@ -556,7 +547,7 @@ public function getLocalization() : View
556547
*
557548
* @since [v1.0]
558549
*/
559-
public function postLocalization(Request $request) : RedirectResponse
550+
public function postLocalization(StoreLocalizationSettings $request) : RedirectResponse
560551
{
561552
if (is_null($setting = Setting::getSettings())) {
562553
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
@@ -599,7 +590,7 @@ public function getAlerts() : View
599590
* @author [A. Gianotto] [<[email protected]>]
600591
* @since [v1.0]
601592
*/
602-
public function postAlerts(Request $request) : RedirectResponse
593+
public function postAlerts(StoreNotificationSettings $request) : RedirectResponse
603594
{
604595
if (is_null($setting = Setting::getSettings())) {
605596
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
@@ -780,7 +771,7 @@ public function getLabels() : View
780771
* @author [A. Gianotto] [<[email protected]>]
781772
* @since [v4.0]
782773
*/
783-
public function postLabels(Request $request) : RedirectResponse
774+
public function postLabels(StoreLabelSettings $request) : RedirectResponse
784775
{
785776
if (is_null($setting = Setting::getSettings())) {
786777
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
@@ -859,26 +850,7 @@ public function getLdapSettings() : View
859850
{
860851
$setting = Setting::getSettings();
861852
$groups = Group::pluck('name', 'id');
862-
863-
864-
/**
865-
* This validator is only temporary (famous last words.) - @snipe
866-
*/
867-
$messages = [
868-
'ldap_username_field.not_in' => '<code>sAMAccountName</code> (mixed case) will likely not work. You should use <code>samaccountname</code> (lowercase) instead. ',
869-
'ldap_auth_filter_query.not_in' => '<code>uid=samaccountname</code> is probably not a valid auth filter. You probably want <code>uid=</code> ',
870-
'ldap_filter.regex' => 'This value should probably not be wrapped in parentheses.',
871-
];
872-
873-
$validator = Validator::make($setting->toArray(), [
874-
'ldap_username_field' => 'not_in:sAMAccountName',
875-
'ldap_auth_filter_query' => 'not_in:uid=samaccountname|required_if:ldap_enabled,1',
876-
'ldap_filter' => 'nullable|regex:"^[^(]"|required_if:ldap_enabled,1',
877-
], $messages);
878-
879-
880-
881-
return view('settings.ldap', compact('setting', 'groups'))->withErrors($validator);
853+
return view('settings.ldap', compact('setting', 'groups'));
882854
}
883855

884856
/**
@@ -887,7 +859,7 @@ public function getLdapSettings() : View
887859
* @author [A. Gianotto] [<[email protected]>]
888860
* @since [v4.0]
889861
*/
890-
public function postLdapSettings(Request $request) : RedirectResponse
862+
public function postLdapSettings(StoreLdapSettings $request) : RedirectResponse
891863
{
892864
if (is_null($setting = Setting::getSettings())) {
893865
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
use Illuminate\Support\Facades\Gate;
7+
8+
class StoreLabelSettings extends FormRequest
9+
{
10+
/**
11+
* Determine if the user is authorized to make this request.
12+
*/
13+
public function authorize(): bool
14+
{
15+
return Gate::allows('superuser');
16+
}
17+
18+
/**
19+
* Get the validation rules that apply to the request.
20+
*
21+
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
22+
*/
23+
public function rules(): array
24+
{
25+
return [
26+
'labels_per_page' => 'numeric',
27+
'labels_width' => 'numeric',
28+
'labels_height' => 'numeric',
29+
'labels_pmargin_left' => 'numeric|nullable',
30+
'labels_pmargin_right' => 'numeric|nullable',
31+
'labels_pmargin_top' => 'numeric|nullable',
32+
'labels_pmargin_bottom' => 'numeric|nullable',
33+
'labels_display_bgutter' => 'numeric|nullable',
34+
'labels_display_sgutter' => 'numeric|nullable',
35+
'labels_fontsize' => 'numeric|min:5',
36+
'labels_pagewidth' => 'numeric|nullable',
37+
'labels_pageheight' => 'numeric|nullable',
38+
'qr_text' => 'max:31|nullable',
39+
];
40+
}
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
use Illuminate\Support\Facades\Gate;
7+
8+
class StoreLdapSettings extends FormRequest
9+
{
10+
/**
11+
* Determine if the user is authorized to make this request.
12+
*/
13+
public function authorize(): bool
14+
{
15+
return Gate::allows('superuser');
16+
}
17+
18+
/**
19+
* Get the validation rules that apply to the request.
20+
*
21+
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
22+
*/
23+
public function rules(): array
24+
{
25+
\Log::error('boop');
26+
return [
27+
'ldap_username_field' => 'not_in:sAMAccountName|required_if:ldap_enabled,1',
28+
'ldap_auth_filter_query' => 'not_in:uid=samaccountname|required_if:ldap_enabled,1',
29+
'ldap_filter' => 'nullable|regex:"^[^(]"|required_if:ldap_enabled,1',
30+
'ldap_server' => 'nullable|required_if:ldap_enabled,1|starts_with:ldap://,ldaps://',
31+
'ldap_uname' => 'nullable|required_if:ldap_enabled,1',
32+
'ldap_pword' => 'nullable|required_if:ldap_enabled,1',
33+
'ldap_basedn' => 'nullable|required_if:ldap_enabled,1',
34+
'ldap_fname_field' => 'nullable|required_if:ldap_enabled,1',
35+
'custom_forgot_pass_url' => 'nullable|url',
36+
];
37+
}
38+
39+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
use Illuminate\Support\Facades\Gate;
7+
8+
class StoreLocalizationSettings extends FormRequest
9+
{
10+
/**
11+
* Determine if the user is authorized to make this request.
12+
*/
13+
public function authorize(): bool
14+
{
15+
return Gate::allows('superuser');
16+
}
17+
18+
/**
19+
* Get the validation rules that apply to the request.
20+
*
21+
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
22+
*/
23+
public function rules(): array
24+
{
25+
return [
26+
'default_currency' => 'required',
27+
'locale' => 'required',
28+
];
29+
}
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use App\Models\Accessory;
6+
use Illuminate\Foundation\Http\FormRequest;
7+
use Illuminate\Support\Facades\Gate;
8+
9+
class StoreNotificationSettings extends FormRequest
10+
{
11+
/**
12+
* Determine if the user is authorized to make this request.
13+
*/
14+
public function authorize(): bool
15+
{
16+
return Gate::allows('superuser');
17+
}
18+
19+
/**
20+
* Get the validation rules that apply to the request.
21+
*
22+
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
23+
*/
24+
public function rules(): array
25+
{
26+
return [
27+
'alert_email' => 'email_array|nullable',
28+
'admin_cc_email' => 'email|nullable',
29+
'alert_threshold' => 'numeric|nullable|gt:0',
30+
'alert_interval' => 'numeric|nullable|gt:0',
31+
'audit_warning_days' => 'numeric|nullable|gt:0',
32+
'due_checkin_days' => 'numeric|nullable|gt:0',
33+
'audit_interval' => 'numeric|nullable|gt:0',
34+
];
35+
}
36+
37+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
use Illuminate\Support\Facades\Gate;
7+
8+
class StoreSecuritySettings extends FormRequest
9+
{
10+
/**
11+
* Determine if the user is authorized to make this request.
12+
*/
13+
public function authorize(): bool
14+
{
15+
return Gate::allows('superuser');
16+
}
17+
18+
/**
19+
* Get the validation rules that apply to the request.
20+
*
21+
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
22+
*/
23+
public function rules(): array
24+
{
25+
return [
26+
'pwd_secure_min' => 'numeric|required|min:8',
27+
'custom_forgot_pass_url' => 'url|nullable',
28+
'privacy_policy_link' => 'nullable|url',
29+
'login_remote_user_enabled' => 'numeric|nullable',
30+
'login_common_disabled' => 'numeric|nullable',
31+
'login_remote_user_custom_logout_url' => 'string|nullable',
32+
'login_remote_user_header_name' => 'string|nullable',
33+
];
34+
}
35+
}

app/Models/Setting.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,7 @@ class Setting extends Model
5151
*/
5252
protected $rules = [
5353
'brand' => 'required|min:1|numeric',
54-
'qr_text' => 'max:31|nullable',
55-
'alert_email' => 'email_array|nullable',
56-
'admin_cc_email' => 'email|nullable',
57-
'default_currency' => 'required',
58-
'locale' => 'required',
59-
'labels_per_page' => 'numeric',
60-
'labels_width' => 'numeric',
61-
'labels_height' => 'numeric',
62-
'labels_pmargin_left' => 'numeric|nullable',
63-
'labels_pmargin_right' => 'numeric|nullable',
64-
'labels_pmargin_top' => 'numeric|nullable',
65-
'labels_pmargin_bottom' => 'numeric|nullable',
66-
'labels_display_bgutter' => 'numeric|nullable',
67-
'labels_display_sgutter' => 'numeric|nullable',
68-
'labels_fontsize' => 'numeric|min:5',
69-
'labels_pagewidth' => 'numeric|nullable',
70-
'labels_pageheight' => 'numeric|nullable',
71-
'login_remote_user_enabled' => 'numeric|nullable',
72-
'login_common_disabled' => 'numeric|nullable',
73-
'login_remote_user_custom_logout_url' => 'string|nullable',
74-
'login_remote_user_header_name' => 'string|nullable',
7554
'thumbnail_max_h' => 'numeric|max:500|min:25',
76-
'pwd_secure_min' => 'numeric|required|min:8',
77-
'alert_threshold' => 'numeric|nullable',
78-
'alert_interval' => 'numeric|nullable',
79-
'audit_warning_days' => 'numeric|nullable',
80-
'due_checkin_days' => 'numeric|nullable',
81-
'audit_interval' => 'numeric|nullable',
82-
'custom_forgot_pass_url' => 'url|nullable',
83-
'privacy_policy_link' => 'nullable|url',
8455
'google_client_id' => 'nullable|ends_with:apps.googleusercontent.com'
8556
];
8657

app/Providers/ValidationServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ public function boot()
3131
Validator::extend('email_array', function ($attribute, $value, $parameters, $validator) {
3232
$value = str_replace(' ', '', $value);
3333
$array = explode(',', $value);
34+
$email_to_validate = [];
3435

3536
foreach ($array as $email) { //loop over values
3637
$email_to_validate['alert_email'][] = $email;
3738
}
3839

3940
$rules = ['alert_email.*'=>'email'];
4041
$messages = [
41-
'alert_email.*'=>trans('validation.email_array'),
42+
'alert_email.*' => trans('validation.custom.email_array'),
4243
];
4344

4445
$validator = Validator::make($email_to_validate, $rules, $messages);

0 commit comments

Comments
 (0)