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