all(); $interaction = InteractionWorkflow::run($trasition, $interaction, $request); $data = new InteractionResource($interaction); return $this->response->message(trans('messages.success.updated', ['Module' => trans('feed::interaction.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('feed/interaction/' . $interaction->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('feed/interaction/' . $interaction->getRouteKey())) ->redirect(); } } /** * Get the interaction and user for the workflow. * * @param PublicRequest $request * @param string $interaction * @param string $user * * @return Response */ public function get(PublicRequest $request, $interaction, $user) { if (!$request->hasValidSignature()) { abort(403, 'This url is expired!'); } $auth = Auth::guard()->getProvider()->getModel(); $user = $auth::findBySignedId($user); Auth::guard()->login($user); $interaction = Interaction::findBySignedId($interaction); $transitions = $this->transitions($interaction, $user); $user = user(); Auth::logout(); return $this->response->setMetaTitle(trans('feed::interaction.name') . ' ' . trans('Approvals')) ->view('feed::public.interaction.workflow') ->layout('mobile') ->data(compact('interaction', 'user', 'transitions')) ->output(); } /** * Display the workflow form for the interaction. * * @param PublicRequest $request * @param string $interaction * @param string $user * * @return Response */ public function post(PublicRequest $request, $interaction, $user) { if (!$request->hasValidSignature()) { abort(403, 'This url is expired!'); } $transition = $request->transition; $auth = Auth::guard()->getProvider()->getModel(); $user = $auth::findBySignedId($user); Auth::guard()->login($user); $interaction = Interaction::findBySignedId($interaction); $user = user(); $interaction = InteractionWorkflow::run($transition, $interaction, $request->all()); Auth::logout(); return response()->json( [ 'status' => 'success', 'url' => $request->url(), ] ); } private function transitions($interaction, $user) { $transitions = []; foreach ($interaction->workflow()->transitions($interaction) as $key => $value) { $name = $value->getName(); $array['url'] = URL::temporarySignedRoute('litecms.interaction.workflow', now()->addMinutes(3), [ 'guard' => 'admin', 'transition' => $name, 'interaction' => $interaction->getSignedId(now()->addMinutes(3)), 'user' => $user->getSignedId(now()->addMinutes(3)), 'trans' => 'en', ] ); $array['name'] = $name; $array['key'] = $name; $array['form'] = $interaction->workflow()->form($value); $array['label'] = trans('feed::interaction.workflow.' . $name); $transitions[] = $array; } return $transitions; } }