-
-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathAccessPermissionFactory.php
More file actions
155 lines (139 loc) · 2.98 KB
/
AccessPermissionFactory.php
File metadata and controls
155 lines (139 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/
namespace Database\Factories;
use App\Models\AccessPermission;
use App\Models\Album;
use App\Models\User;
use App\Models\UserGroup;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\AccessPermission>
*/
class AccessPermissionFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = AccessPermission::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return
[
'is_link_required' => true,
'grants_full_photo_access' => false,
'grants_download' => false,
'grants_upload' => false,
'grants_edit' => false,
'grants_delete' => false,
];
}
public function public()
{
return $this->state(function (array $attributes) {
return [
'user_id' => null,
'user_group_id' => null,
];
});
}
public function locked()
{
return $this->state(function (array $attributes) {
return [
'password' => Hash::make('password'),
];
});
}
public function for_user(User $user)
{
return $this->state(function (array $attributes) use ($user) {
return [
'user_id' => $user->id,
'user_group_id' => null,
];
})->afterCreating(function (AccessPermission $perm) {
$perm->load('album', 'user', 'user_group');
});
}
public function for_user_group(UserGroup $userGroup)
{
return $this->state(function (array $attributes) use ($userGroup) {
return [
'user_id' => null,
'user_group_id' => $userGroup->id,
];
})->afterCreating(function (AccessPermission $perm) {
$perm->load('album', 'user', 'user_group');
});
}
public function grants_edit()
{
return $this->state(function (array $attributes) {
return [
'grants_edit' => true,
];
});
}
public function grants_delete()
{
return $this->state(function (array $attributes) {
return [
'grants_delete' => true,
];
});
}
public function grants_upload()
{
return $this->state(function (array $attributes) {
return [
'grants_upload' => true,
];
});
}
public function grants_download()
{
return $this->state(function (array $attributes) {
return [
'grants_download' => true,
];
});
}
public function grants_full_photo()
{
return $this->state(function (array $attributes) {
return [
'grants_full_photo_access' => true,
];
});
}
public function visible()
{
return $this->state(function (array $attributes) {
return [
'is_link_required' => false,
];
});
}
public function for_album(Album $album)
{
return $this->state(function (array $attributes) use ($album) {
return [
'base_album_id' => $album->id,
];
})->afterCreating(function (AccessPermission $perm) {
$perm->load('album', 'user', 'user_group');
});
}
}