File tree Expand file tree Collapse file tree 4 files changed +178
-3
lines changed
app/Http/Requests/V1/TimeEntry
tests/Unit/Endpoint/Api/V1 Expand file tree Collapse file tree 4 files changed +178
-3
lines changed Original file line number Diff line number Diff line change 1010use App \Models \Project ;
1111use App \Models \Tag ;
1212use App \Models \Task ;
13+ use App \Service \PermissionStore ;
1314use Illuminate \Contracts \Validation \ValidationRule ;
1415use Illuminate \Database \Eloquent \Builder ;
16+ use Illuminate \Support \Facades \Auth ;
1517use Korridor \LaravelModelValidationRules \Rules \ExistsEloquent ;
1618
1719/**
@@ -42,7 +44,16 @@ public function rules(): array
4244 'required_with:task_id ' ,
4345 ExistsEloquent::make (Project::class, null , function (Builder $ builder ): Builder {
4446 /** @var Builder<Project> $builder */
45- return $ builder ->whereBelongsTo ($ this ->organization , 'organization ' );
47+ $ builder = $ builder ->whereBelongsTo ($ this ->organization , 'organization ' );
48+
49+ // If user doesn't have 'all' permission for time entries or projects, only allow access to public projects or projects they're a member of
50+ $ permissionStore = app (PermissionStore::class);
51+ if (! $ permissionStore ->has ($ this ->organization , 'time-entries:create:all ' )
52+ && ! $ permissionStore ->has ($ this ->organization , 'projects:view:all ' )) {
53+ $ builder = $ builder ->visibleByEmployee (Auth::user ());
54+ }
55+
56+ return $ builder ;
4657 })->uuid (),
4758 ],
4859 // ID of the task that the time entry should belong to
Original file line number Diff line number Diff line change 1010use App \Models \Project ;
1111use App \Models \Tag ;
1212use App \Models \Task ;
13+ use App \Service \PermissionStore ;
1314use Illuminate \Contracts \Validation \ValidationRule ;
1415use Illuminate \Database \Eloquent \Builder ;
16+ use Illuminate \Support \Facades \Auth ;
1517use Korridor \LaravelModelValidationRules \Rules \ExistsEloquent ;
1618
1719/**
@@ -54,7 +56,16 @@ public function rules(): array
5456 'required_with:task_id ' ,
5557 ExistsEloquent::make (Project::class, null , function (Builder $ builder ): Builder {
5658 /** @var Builder<Project> $builder */
57- return $ builder ->whereBelongsTo ($ this ->organization , 'organization ' );
59+ $ builder = $ builder ->whereBelongsTo ($ this ->organization , 'organization ' );
60+
61+ // If user doesn't have 'all' permission for time entries or projects, only allow access to public projects or projects they're a member of
62+ $ permissionStore = app (PermissionStore::class);
63+ if (! $ permissionStore ->has ($ this ->organization , 'time-entries:update:all ' )
64+ && ! $ permissionStore ->has ($ this ->organization , 'projects:view:all ' )) {
65+ $ builder = $ builder ->visibleByEmployee (Auth::user ());
66+ }
67+
68+ return $ builder ;
5869 })->uuid (),
5970 ],
6071 // ID of the task that the time entry should belong to
Original file line number Diff line number Diff line change 1010use App \Models \Project ;
1111use App \Models \Tag ;
1212use App \Models \Task ;
13+ use App \Service \PermissionStore ;
1314use Illuminate \Contracts \Validation \ValidationRule ;
1415use Illuminate \Database \Eloquent \Builder ;
16+ use Illuminate \Support \Facades \Auth ;
1517use Korridor \LaravelModelValidationRules \Rules \ExistsEloquent ;
1618
1719/**
@@ -42,7 +44,16 @@ public function rules(): array
4244 'required_with:task_id ' ,
4345 ExistsEloquent::make (Project::class, null , function (Builder $ builder ): Builder {
4446 /** @var Builder<Project> $builder */
45- return $ builder ->whereBelongsTo ($ this ->organization , 'organization ' );
47+ $ builder = $ builder ->whereBelongsTo ($ this ->organization , 'organization ' );
48+
49+ // If user doesn't have 'all' permission for time entries or projects, only allow access to public projects or projects they're a member of
50+ $ permissionStore = app (PermissionStore::class);
51+ if (! $ permissionStore ->has ($ this ->organization , 'time-entries:update:all ' )
52+ && ! $ permissionStore ->has ($ this ->organization , 'projects:view:all ' )) {
53+ $ builder = $ builder ->visibleByEmployee (Auth::user ());
54+ }
55+
56+ return $ builder ;
4657 })->uuid (),
4758 ],
4859 // ID of the task that the time entry should belong to
You can’t perform that action at this time.
0 commit comments