public function testBuildDeletePost() { $build = Build::find(2); $data = array('confirm-delete' => '1'); $response = $this->call('POST', '/modpack/build/' . $build->id . '?action=delete', $data); $this->assertRedirectedTo('modpack/view/' . $build->modpack->id); }
/** * Run the database seeds. * * @return void */ public function run() { Eloquent::unguard(); //$this->call('UserTableSeeder'); $this->call('ModpackTableTestSeeder'); $this->call('ModTableTestSeeder'); $this->call('ClientTableTestSeeder'); $this->call('KeyTableTestSeeder'); DB::table('build_modversion')->delete(); $testbuild = Build::find(1); //Add testmodversion to testbuild $testbuild->modversions()->attach(1); }
/** * AJAX Methods for Modpack Manager **/ public function action_modify($action = null) { if (empty($action)) { return Response::error('500'); } switch ($action) { case "version": $affected = DB::table('build_modversion')->where('id', '=', Input::get('pivot_id'))->update(array('modversion_id' => Input::get('version'))); return Response::json(array('success' => 'Rows Affected: ' . $affected)); break; case "delete": $affected = DB::table('build_modversion')->where('id', '=', Input::get('pivot_id'))->delete(); return Response::json(array('success' => 'Rows Affected: ' . $affected)); break; case "add": $build = Build::find(Input::get('build')); $mod = Mod::where('name', '=', Input::get('mod-name'))->first(); $ver = ModVersion::where('mod_id', '=', $mod->id)->where('version', '=', Input::get('mod-version'))->first(); $build->modversions()->attach($ver->id); return Response::json(array('pretty_name' => $mod->pretty_name, 'version' => $ver->version)); break; case "recommended": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('recommended'); $modpack->recommended = $new_version; $modpack->save(); return Response::json(array("success" => "Updated " . $modpack->name . "'s recommended build to " . $new_version, "version" => $new_version)); break; case "latest": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('latest'); $modpack->latest = $new_version; $modpack->save(); return Response::json(array("success" => "Updated " . $modpack->name . "'s latest build to " . $new_version, "version" => $new_version)); break; case "published": $build = Build::find(Input::get('build')); $published = Input::get('published'); $build->is_published = $published ? true : false; $build->save(); return Response::json(array("success" => "Updated build " . $build->version . "'s published status.")); } }
} }); Route::filter('auth', function () { if (Auth::guest()) { return Redirect::to('login'); } }); Route::filter('perm', function ($check) { $perm = (array) Auth::user()->permission; $perm = $perm['attributes']; if (!$perm['solder_full'] && !$perm[$check]) { return Redirect::to('dashboard')->with('permission', 'You do not have permission to access this area.'); } }); Route::filter('modpack', function ($modpack) { $perm = Auth::user()->permission; if (!$perm->solder_full && !in_array($modpack, $perm->modpacks)) { return Redirect::to('dashboard')->with('permission', 'You do not have permission to access this area.'); } }); Route::filter('build', function ($build) { $perm = Auth::user()->permission; $build = Build::find($build); if (empty($build)) { return Redirect::to('dashboard'); } $modpack = $build->modpack; if (!$perm->solder_full && !in_array($modpack->id, $perm->modpacks)) { return Redirect::to('dashboard')->with('permission', 'You do not have permission to access this area.'); } });
/** * AJAX Methods for Modpack Manager **/ public function anyModify($action = null) { if (!Request::ajax()) { return Response::view('errors.missing', array(), 404); } if (empty($action)) { return Response::view('errors.500', array(), 500); } switch ($action) { case "version": $version_id = Input::get('version'); $modversion_id = Input::get('modversion_id'); $affected = DB::table('build_modversion')->where('build_id', '=', Input::get('build_id'))->where('modversion_id', '=', $modversion_id)->update(array('modversion_id' => $version_id)); if ($affected == 0) { if ($modversion_id != $version_id) { $status = 'failed'; } else { $status = 'aborted'; } } else { $status = 'success'; } return Response::json(array('status' => $status, 'reason' => 'Rows Affected: ' . $affected)); break; case "delete": $affected = DB::table('build_modversion')->where('build_id', '=', Input::get('build_id'))->where('modversion_id', '=', Input::get('modversion_id'))->delete(); $status = 'success'; if ($affected == 0) { $status = 'failed'; } return Response::json(array('status' => $status, 'reason' => 'Rows Affected: ' . $affected)); break; case "add": $build = Build::find(Input::get('build')); $mod = Mod::where('name', '=', Input::get('mod-name'))->first(); $ver = Modversion::where('mod_id', '=', $mod->id)->where('version', '=', Input::get('mod-version'))->first(); $affected = DB::table('build_modversion')->where('build_id', '=', $build->id)->where('modversion_id', '=', $ver->id)->get(); $duplicate = !empty($affected); if ($duplicate) { return Response::json(array('status' => 'failed', 'reason' => 'Duplicate Modversion found')); } else { $build->modversions()->attach($ver->id); return Response::json(array('status' => 'success', 'pretty_name' => $mod->pretty_name, 'version' => $ver->version)); } break; case "recommended": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('recommended'); $modpack->recommended = $new_version; $modpack->save(); Cache::forget('modpack.' . $modpack->slug); return Response::json(array("success" => "Updated " . $modpack->name . "'s recommended build to " . $new_version, "version" => $new_version)); break; case "latest": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('latest'); $modpack->latest = $new_version; $modpack->save(); Cache::forget('modpack.' . $modpack->slug); return Response::json(array("success" => "Updated " . $modpack->name . "'s latest build to " . $new_version, "version" => $new_version)); break; case "published": $build = Build::find(Input::get('build')); $published = Input::get('published'); $build->is_published = $published ? true : false; $build->save(); return Response::json(array("success" => "Updated build " . $build->version . "'s published status.")); case "private": $build = Build::find(Input::get('build')); $private = Input::get('private'); $build->private = $private ? true : false; $build->save(); return Response::json(array("success" => "Updated build " . $build->version . "'s private status.")); } }