diff --git a/app/Forms/RruleForm.php b/app/Forms/RruleForm.php index 0fcf23c..a86d38b 100644 --- a/app/Forms/RruleForm.php +++ b/app/Forms/RruleForm.php @@ -2,6 +2,7 @@ namespace App\Forms; +use Carbon\Carbon; use Kris\LaravelFormBuilder\Form; class RruleForm extends Form @@ -9,6 +10,8 @@ class RruleForm extends Form public function buildForm() { $order = $this->getData('entity'); + $now = Carbon::now(); + $rrule = 'DTSTART:'.$now->format('Ym??')."T??0000Z\nRRULE:FREQ=DAILY;COUNT=?;INTERVAL=1;WKST=MO;BYDAY=MO,TU,WE,TH,FR,SA,SU"; if ($order) { $this->add('order_id', 'hidden', [ 'label' => $order->title, @@ -35,6 +38,7 @@ public function buildForm() ->add('string', 'textarea', [ 'label' => '计划', 'rules' => 'required', + 'value' => $rrule, 'attr' => [ 'rows' => 3, 'placeholder' => "DTSTART:20190330T180000Z\nRRULE:FREQ=DAILY;COUNT=5;INTERVAL=1;WKST=MO;BYDAY=TU", diff --git a/app/Http/Controllers/RruleController.php b/app/Http/Controllers/RruleController.php index 5fcdc34..f20567f 100644 --- a/app/Http/Controllers/RruleController.php +++ b/app/Http/Controllers/RruleController.php @@ -2,15 +2,15 @@ namespace App\Http\Controllers; -use App\Forms\Edit\RruleForm as EditForm; -use App\Forms\RruleForm as CreateForm; +use Carbon\Carbon; use App\Models\Order; use App\Models\Rrule; -use Carbon\Carbon; -// use App\Repositories\RruleRepository; use Illuminate\Http\Request; +use App\Forms\RruleForm as CreateForm; +// use App\Repositories\RruleRepository; use Illuminate\Support\Facades\Session; use Kris\LaravelFormBuilder\FormBuilder; +use App\Forms\Edit\RruleForm as EditForm; use Kris\LaravelFormBuilder\FormBuilderTrait; class RruleController extends Controller @@ -25,7 +25,7 @@ class RruleController extends Controller public function __construct() { // $this->repository = $repository; - $this->middleware(['admin']); + // $this->middleware(['admin']); } /** @@ -38,6 +38,7 @@ public function index() // $limit = 10; // $columns = ['*']; // $rrules = $this->repository->paginate($limit, $columns); + $this->authorize('viewAny', Rrule::class); $rrules = Rrule::with( 'order', 'order.user', @@ -60,6 +61,7 @@ public function index() */ public function create(Order $order) { + $this->authorize('create', Rrule::class); $form = $this->form(CreateForm::class, [ 'method' => 'POST', 'url' => action('RruleController@store'), @@ -76,6 +78,7 @@ public function create(Order $order) */ public function store(Request $request, FormBuilder $formBuilder) { + $this->authorize('create', Rrule::class); $form = $formBuilder->create(CreateForm::class); if (! $form->isValid()) { @@ -119,6 +122,7 @@ public function show(Rrule $rrule) */ public function edit(Rrule $rrule) { + $this->authorize('update', $rrule); $form = $this->form( EditForm::class, [ @@ -140,6 +144,7 @@ public function edit(Rrule $rrule) */ public function update(Request $request, Rrule $rrule, FormBuilder $formBuilder) { + $this->authorize('update', $rrule); $form = $this->form(EditForm::class); // dd($rrule->toArray(),$form->isValid(),$form->getErrors()); if (! $form->isValid()) { diff --git a/app/Policies/RrulePolicy.php b/app/Policies/RrulePolicy.php new file mode 100644 index 0000000..35b7d9d --- /dev/null +++ b/app/Policies/RrulePolicy.php @@ -0,0 +1,100 @@ + 'View any Rrule']); +// Permission::create(['name' => 'Create a Rrule']); +// Permission::create(['name' => 'Update any Rrule']); +// Permission::create(['name' => 'View any ClassRecord']); + +class RrulePolicy +{ + use HandlesAuthorization; + + /** + * Determine whether the user can view any rrules. + * + * @param \App\User $user + * @return mixed + */ + public function viewAny(User $user) + { + return $user->hasAnyPermission(['View any Rrule']); + } + + /** + * Determine whether the user can view the rrule. + * + * @param \App\User $user + * @param \App\Models\Rrule $rrule + * @return mixed + */ + public function view(User $user, Rrule $rrule) + { + return $user->hasAnyPermission(['View any Rrule']); + } + + /** + * Determine whether the user can create rrules. + * + * @param \App\User $user + * @return mixed + */ + public function create(User $user) + { + return $user->hasAnyPermission(['Create a Rrule']); + } + + /** + * Determine whether the user can update the rrule. + * + * @param \App\User $user + * @param \App\Models\Rrule $rrule + * @return mixed + */ + public function update(User $user, Rrule $rrule) + { + return $user->hasAnyPermission(['Update any Rrule']); + } + + /** + * Determine whether the user can delete the rrule. + * + * @param \App\User $user + * @param \App\Models\Rrule $rrule + * @return mixed + */ + public function delete(User $user, Rrule $rrule) + { + // + } + + /** + * Determine whether the user can restore the rrule. + * + * @param \App\User $user + * @param \App\Models\Rrule $rrule + * @return mixed + */ + public function restore(User $user, Rrule $rrule) + { + // + } + + /** + * Determine whether the user can permanently delete the rrule. + * + * @param \App\User $user + * @param \App\Models\Rrule $rrule + * @return mixed + */ + public function forceDelete(User $user, Rrule $rrule) + { + // + } +} diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 71ac7e7..6bd9c8f 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -2,23 +2,25 @@ namespace App\Providers; -use App\Models\Agency; -use App\Models\ClassRecord; use App\Models\Order; -use App\Models\Profile; +use App\Models\Rrule; +use App\Models\Video; +use App\Models\Agency; use App\Models\Social; +use App\Models\Profile; use App\Models\Student; use App\Models\Teacher; -use App\Models\Video; -use App\Policies\AgencyPolicy; -use App\Policies\ClassRecordPolicy; +use App\Models\ClassRecord; use App\Policies\OrderPolicy; +use App\Policies\RrulePolicy; +use App\Policies\VideoPolicy; +use App\Policies\AgencyPolicy; use App\Policies\ProfilePolicy; use App\Policies\StudentPolicy; use App\Policies\TeacherPolicy; -use App\Policies\VideoPolicy; -use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; +use App\Policies\ClassRecordPolicy; use Illuminate\Support\Facades\Gate; +use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; class AuthServiceProvider extends ServiceProvider { @@ -36,6 +38,7 @@ class AuthServiceProvider extends ServiceProvider Profile::class => ProfilePolicy::class, Video::class => VideoPolicy::class, Order::class => OrderPolicy::class, + Rrule::class => RrulePolicy::class, ]; /** diff --git a/resources/views/layouts/menu4user.blade.php b/resources/views/layouts/menu4user.blade.php index a33faf5..a0f5c44 100644 --- a/resources/views/layouts/menu4user.blade.php +++ b/resources/views/layouts/menu4user.blade.php @@ -9,4 +9,22 @@ -@endrole \ No newline at end of file +@endrole + +@can('View any Order') + +@endcan + +@can('View any Student') + +@endcan + +@can('View any ClassRecord') + +@endcan \ No newline at end of file