1
0

StoreStatusEditRequest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Http\Requests\Status;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use App\Media;
  5. use App\Status;
  6. use Closure;
  7. class StoreStatusEditRequest extends FormRequest
  8. {
  9. /**
  10. * Determine if the user is authorized to make this request.
  11. */
  12. public function authorize(): bool
  13. {
  14. $profile = $this->user()->profile;
  15. if($profile->status != null) {
  16. return false;
  17. }
  18. if($profile->unlisted == true && $profile->cw == true) {
  19. return false;
  20. }
  21. $types = [
  22. "photo",
  23. "photo:album",
  24. "photo:video:album",
  25. "reply",
  26. "text",
  27. "video",
  28. "video:album"
  29. ];
  30. $scopes = ['public', 'unlisted', 'private'];
  31. $status = Status::whereNull('reblog_of_id')->whereIn('type', $types)->whereIn('scope', $scopes)->find($this->route('id'));
  32. return $status && $this->user()->profile_id === $status->profile_id;
  33. }
  34. /**
  35. * Get the validation rules that apply to the request.
  36. *
  37. * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
  38. */
  39. public function rules(): array
  40. {
  41. return [
  42. 'status' => 'sometimes|max:'.config('pixelfed.max_caption_length', 500),
  43. 'spoiler_text' => 'nullable|string|max:140',
  44. 'sensitive' => 'sometimes|boolean',
  45. 'media_ids' => [
  46. 'nullable',
  47. 'required_without:status',
  48. 'array',
  49. 'max:' . config('pixelfed.max_album_length'),
  50. function (string $attribute, mixed $value, Closure $fail) {
  51. Media::whereProfileId($this->user()->profile_id)
  52. ->where(function($query) {
  53. return $query->whereNull('status_id')
  54. ->orWhere('status_id', '=', $this->route('id'));
  55. })
  56. ->findOrFail($value);
  57. },
  58. ],
  59. 'location' => 'sometimes|nullable',
  60. 'location.id' => 'sometimes|integer|min:1|max:128769',
  61. 'location.country' => 'required_with:location.id',
  62. 'location.name' => 'required_with:location.id',
  63. ];
  64. }
  65. }