This commit is contained in:
Richard Dern
2022-01-12 00:35:37 +01:00
commit 400e3d01f1
1363 changed files with 57778 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Http\Requests\Documents;
use App\Models\Folder;
use App\Models\Group;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
$folder = Folder::find($this->folder_id);
return $this->user()->can('createBookmarkIn', $folder);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'url' => [
'required',
'url',
],
'group_id' => [
'required',
Rule::exists(Group::class, 'id'),
],
'folder_id' => [
'required',
Rule::exists(Folder::class, 'id'),
],
];
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation()
{
$this->merge([
'url' => urldecode($this->url),
]);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Http\Requests\Folders;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class SetPermissionsRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->user()->can('setPermission', $this->folder);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'ability' => [
'nullable',
Rule::in([
'can_create_folder',
'can_update_folder',
'can_delete_folder',
'can_create_document',
'can_delete_document',
]),
],
'granted' => [
'nullable',
'boolean',
],
'user_id' => [
'nullable',
Rule::exists('users', 'id'),
],
];
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Http\Requests\Folders;
use App\Models\Folder;
use App\Models\Group;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
$parentFolder = Folder::find($this->parent_id);
return $this->user()->can('createIn', $parentFolder);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$groupId = $this->group_id;
return [
'title' => [
'required',
'max:255',
],
// Parent folder ID must exist and in the same group as requested
'parent_id' => [
'required',
Rule::exists(Folder::class, 'id')->where(function ($query) use ($groupId) {
$query->where('group_id', '=', $groupId);
}),
],
'group_id' => [
'required',
Rule::exists(Group::class, 'id'),
],
];
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace App\Http\Requests\Folders;
use App\Models\Folder;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
if (empty($this->parent_id)) {
return 'root' === $this->folder->type;
}
$parent = Folder::find($this->parent_id);
return $this->user()->can('createIn', $parent) && $this->user()->can('update', $this->folder);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$groupId = $this->group_id;
return [
'title' => [
'required',
'max:255',
],
'parent_id' => [
'nullable',
Rule::exists('App\Models\Folder', 'id')->where(function ($query) use ($groupId) {
$query->where('group_id', '=', $groupId);
}),
],
'group_id' => [
'required',
Rule::exists('App\Models\Group', 'id'),
],
'is_expanded' => [
'sometimes',
'boolean',
],
];
}
/**
* Configure the validator instance.
*
* @param \Illuminate\Validation\Validator $validator
*/
public function withValidator($validator)
{
$validator->after(function ($validator) {
if ($this->isMoving()) {
if ('folder' !== $this->folder->type) {
// Trying to move a "special" folder like root
$validator->errors()->add('parent_id', __('You cannot move this folder'));
} elseif ($this->targetParentIsDescendant()) {
$validator->errors()->add('parent_id', __('You cannot move this folder to a descendant'));
}
}
});
}
/**
* Return a boolean value indicating if we're moving a folder.
*
* @return bool
*/
private function isMoving()
{
return $this->parent_id !== $this->folder->parent_id;
}
/**
* Return a boolean value indicating if we're trying to move a folder into
* one of its descendants.
*
* @return bool
*/
private function targetParentIsDescendant()
{
$parent = Folder::find($this->parent_id);
while ($parent) {
if ($parent->id === $this->folder->id) {
return true;
}
$parent = $parent->parent;
}
return false;
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Http\Requests\Groups;
use Illuminate\Foundation\Http\FormRequest;
class InviteUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->user()->can('invite', $this->group);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => [
'required',
'email',
],
];
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Http\Requests\Groups;
use Illuminate\Foundation\Http\FormRequest;
class StoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => [
'required',
],
'description' => [
'nullable',
],
'invite_only' => [
'boolean',
],
'auto_accept_users' => [
'boolean',
],
];
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Http\Requests\Groups;
use Illuminate\Foundation\Http\FormRequest;
class UpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->user()->can('update', $this->group);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => [
'required',
],
'description' => [
'nullable',
],
'invite_only' => [
'boolean',
],
'auto_accept_users' => [
'boolean',
],
];
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreHighlightRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'expression' => [
'required',
],
'color' => [
'required',
'regex:/^#[0-9a-f]{3,6}$/i',
],
];
}
}