Exemple #1
0
 public function action_update($id)
 {
     // RESTful update from Backbone
     $officer = Officer::find($id);
     $json = Input::json(true);
     if (isset($json["command"])) {
         if (Auth::officer()->is_role_or_higher(Officer::ROLE_SUPER_ADMIN) && !$officer->is_role_or_higher(Officer::ROLE_SUPER_ADMIN) && Auth::officer()->id != $officer->id) {
             if ($json["command"] == "ban") {
                 $officer->ban();
             }
             if ($json["command"] == "unban") {
                 $officer->unban();
             }
             $officer->save();
             $officer = Officer::find($id);
         }
         return Response::json($officer->to_array());
     }
     // We can update the officer's role if we are an Admin or a Super Admin.
     // If we're a Super Admin, we can change the roles of other Super Admins.
     // Super Admins can never modify their own role.
     if (Auth::officer()->is_role_or_higher(Officer::ROLE_ADMIN)) {
         if (isset($json["role"]) && ($officer->role != Officer::ROLE_SUPER_ADMIN || Auth::officer()->is_role_or_higher(Officer::ROLE_SUPER_ADMIN)) && ($officer->role != Officer::ROLE_SUPER_ADMIN || Auth::officer()->id != $officer->id)) {
             $officer->role = $json["role"];
         }
     }
     $officer->save();
     return Response::json($officer->to_array());
 }
 /**
  * Show the form for editing the specified officer.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $menu = Menu::where('tipe', Sentry::getUser()->last_name)->get();
     $officer = Officer::find(Crypt::decrypt($id));
     return View::make('officers.edit', compact('officer'))->withTitle('Ubah')->with('menu', $menu);
 }