|
@@ -19,7 +19,7 @@ class CustomFieldController extends Controller
|
|
|
*/
|
|
|
public function index(Request $request)
|
|
|
{
|
|
|
- $customFields = CustomField::query()->filter($request->all())->get();
|
|
|
+ $customFields = CustomField::query()->allowed()->filter($request->all())->get();
|
|
|
|
|
|
return CustomFieldResource::collection($customFields);
|
|
|
}
|
|
@@ -29,24 +29,27 @@ class CustomFieldController extends Controller
|
|
|
*/
|
|
|
public function store(CreateOrUpdateRequest $request)
|
|
|
{
|
|
|
- if (Auth::user()->super_admin) {
|
|
|
- $namingRule = NamingRule::query()->where("id", $request->group)->first();
|
|
|
- if (!in_array($request->group, config("custom-field.groups")) && !$namingRule) {
|
|
|
- return $this->forbidden("Operation without permission");
|
|
|
- }
|
|
|
- } else {
|
|
|
- $namingRule = NamingRule::query()->where("company_id", Auth::user()->company_id)->where("id", $request->group)->first();
|
|
|
- if (! $namingRule) {
|
|
|
- return $this->forbidden('Naming rule does not exist');
|
|
|
- }
|
|
|
+ $namingRule = NamingRule::query()->where("id", $request->group)->first();
|
|
|
+ if (!in_array($request->group, config("custom-field.groups")) && !$namingRule) {
|
|
|
+ return $this->forbidden("Operation without permission");
|
|
|
}
|
|
|
|
|
|
- CustomField::query()->updateOrCreate([
|
|
|
+ $global = Auth::user()->super_admin ? 1 : 0;
|
|
|
+
|
|
|
+ if ($global === 1 && !Auth::user()->super_admin) {
|
|
|
+ return $this->forbidden("Cannot change global Custom Field without super admin permissions");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ CustomField::query()->allowed()->updateOrCreate([
|
|
|
'group' => $request->group,
|
|
|
'key' => $request->key,
|
|
|
- ], $request->all());
|
|
|
+ 'company_id'=>Auth::user()->company_id,
|
|
|
+ 'global'=>$global,
|
|
|
+ ],$request->all());
|
|
|
|
|
|
return $this->created();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public function groups()
|
|
@@ -72,7 +75,7 @@ class CustomFieldController extends Controller
|
|
|
*/
|
|
|
public function show(string $id)
|
|
|
{
|
|
|
- $field = CustomField::query()->findOrFail($id);
|
|
|
+ $field = CustomField::query()->allowed()->findOrFail($id);
|
|
|
|
|
|
return new CustomFieldResource($field);
|
|
|
}
|
|
@@ -91,7 +94,11 @@ class CustomFieldController extends Controller
|
|
|
public function destroy(string $id)
|
|
|
{
|
|
|
//
|
|
|
- $field = CustomField::query()->findOrFail($id);
|
|
|
+ $field = CustomField::query()->allowed()->findOrFail($id);
|
|
|
+
|
|
|
+ if ($field->global === 1 && !Auth::user()->super_admin) {
|
|
|
+ return $this->forbidden("Cannot delete global Custom Field without super admin permissions");
|
|
|
+ }
|
|
|
$field->delete();
|
|
|
return $this->noContent();
|
|
|
}
|