/** * a section can only be archived by the * the moderator of the parent section * * @return bool */ public function authorize() { $return = false; $section = \Nexus\Section::findOrFail($this->section); $parent = \Nexus\Section::findOrFail($section->parent_id); if (\Auth::user()->id === $parent->moderator->id) { $return = true; } else { $return = false; } return $return; }
/** * Determine if the user is authorized to make this request. * * For the Current Section * user must be the moderator * * For Subsections all these must be true! * [1] a subsection can be edited by the moderator of its parent section * [2] a subsection cannot be moved into a decedent section * [3] a subsection can only be moved into a section the parent section moderator moderates * * @return bool */ public function authorize() { $return = false; $formName = key($this::input('form')); $formValues = $this::input('form')[$formName]; // dd($formValues, $formName); $this->session()->flash('form', $formName); if (!\Auth::check()) { $return = false; } // if $formValues['parent_id'] is null then we are editing the main menu $section = \Nexus\Section::findOrFail($formValues['id']); // are we editing the current section OR a sub section if ($formValues['id'] === $formValues['current_section']) { // current section if ($section->moderator->id == \Auth::user()->id) { $return = true; } else { $return = false; } } else { // sub section $destination = \Nexus\Section::findOrFail($formValues['parent_id']); // [1] a subsection can be edited by the moderator of its parent section if ($section->parent->moderator->id == \Auth::user()->id) { $updated_by_parent_moderator = true; } else { $updated_by_parent_moderator = false; } // [2] a subsection cannot be moved into a decedent section $decedents = \Nexus\Helpers\SectionHelper::allChildSections($section); if ($decedents->where('id', $destination->id)->count() > 0) { $destination_not_child = false; } else { $destination_not_child = true; } // [3] a subsection can only be moved into a section the moderator moderates if ($destination->moderator->id == \Auth::user()->id) { $destination_moderated_by_editor = true; } else { $destination_moderated_by_editor = false; } // if all conditions are matched then this is allowed if ($updated_by_parent_moderator && $destination_not_child && $destination_moderated_by_editor) { $return = true; } else { $return = false; } } return $return; }
/** * a topic can only be restored by * the moderator of the section and destination section * * @return bool */ public function authorize() { $return = false; $currentUserID = \Auth::user()->id; $trashedTopic = \Nexus\Topic::onlyTrashed()->findOrFail($this->topic); $originalSection = \Nexus\Section::withTrashed()->findOrFail($trashedTopic->section_id); $destinationSection = \Nexus\Section::findOrFail($this->destination); if ($destinationSection->moderator->id === $currentUserID && $originalSection->moderator->id === $currentUserID) { $return = true; } else { $return = false; } return $return; }
/** * a user can create a section if they * moderate the current section * * @return bool */ public function authorize() { $return = false; $formName = "sectionCreate"; $formValues = $this::input('form')[$formName]; $this->session()->flash('form', $formName); $parentSection = \Nexus\Section::findOrFail($formValues['parent_id']); if (\Auth::user()->id == $parentSection->moderator->id) { $return = true; } else { $return = false; } return $return; }
/** * a section can only be restored by * [1] the moderator of both the parent and destination sections * or * [2] the moderator of the section and destination section * * @return bool */ public function authorize() { $return = false; $currentUserID = \Auth::user()->id; $trashedSection = \Nexus\Section::onlyTrashed()->findOrFail($this->section); $destinationSection = \Nexus\Section::findOrFail($this->destination); if ($destinationSection->moderator->id === $currentUserID) { // case [1] if ($trashedSection->parent != null) { if ($trashedSection->parent->moderator->id === $currentUserID) { $return = true; } } // case [2] if ($trashedSection->moderator->id === $currentUserID) { $return = true; } } return $return; }
/** * topic can be created by moderators of the current section or bbs administrators * * user should be * logged in * user administrator | user moderator * * @return bool */ public function authorize() { $return = false; $formName = "topicCreate"; $formValues = $this::input('form')[$formName]; $this->session()->flash('form', $formName); if (\Auth::check()) { $authUser = \Auth::user(); $section = Section::findOrFail($formValues['section_id']); // is the user an administrator if ($authUser->administrator) { $return = true; } // or the user is the section moderator if ($authUser->id === $section->moderator->id) { $return = true; } } else { $return = false; } return $return; }
public function authorize() { $return = false; $topic = Topic::findOrFail($this::input('topic_id')); $section = Section::findOrFail($topic->section_id); if (\Auth::check()) { $authUser = \Auth::user(); // is the user an administrator if ($authUser->administrator) { $return = true; } // OR is the user the moderator if ($authUser->id === $section->moderator->id) { $return = true; } // OR is the topic NOT ready only if (!$topic->readonly) { $return = true; } } else { $return = false; } return $return; }
private function migrateSections() { $this->info('Importing Sections'); $errorCount = 0; if (!\Nexus\Section::first()) { $count = \DB::select('select count(section_id) as count from sectiontable')[0]->count; $this->line("Found {$count} sections "); $this->line("Migrating Sections "); $bar = $this->output->createProgressBar($count); $classicSections = \DB::table('sectiontable')->get(); foreach ($classicSections as $classicSection) { try { $newSection = new \Nexus\Section(); $newSection->id = $classicSection->section_id; $newSection->title = $classicSection->section_title; $newSection->intro = $classicSection->section_intro; $newSection->user_id = $classicSection->user_id; $newSection->weight = $classicSection->section_weight; $newSection->save(); $bar->advance(); } catch (\Exception $e) { $errorCount++; \Log::error('Nexus:upgrade - Failed to add section ' . $e); } } $bar->finish(); $this->line("\nMigration Complete"); $this->line("Jumbling Sections into Subsections"); $bar = $this->output->createProgressBar($count); foreach ($classicSections as $classicSection) { try { $newSection = \Nexus\Section::findOrFail($classicSection->section_id); $newSection->parent_id = $classicSection->parent_id; $newSection->save(); $bar->advance(); } catch (\Exception $e) { $errorCount++; \Log::error('Nexus:upgrade - Failed to add parent to section ' . $e); } } unset($classicSections); $bar->finish(); if ($errorCount) { $this->error("\nEncountered {$errorCount} errors. See log for details"); } $this->info("\nSections Complete\n"); } else { $this->error('Upgrade: found existing sections - skipping Sections'); } }
/** * Remove the specified resource from storage. * * @param section id $id * @param Section\Destroy $request * @return Response */ public function destroy(Requests\Section\DestroyRequest $request, $id) { $section = \Nexus\Section::findOrFail($id); $parent_id = $section->parent_id; $section->delete(); $redirect = action('Nexus\\SectionController@show', ['id' => $parent_id]); return redirect($redirect); }
public function topic(Requests\topic\RestoreRequest $request, $id) { $trashedTopic = \Nexus\Topic::onlyTrashed()->findOrFail($id); $destinationSection = \Nexus\Section::findOrFail($request->destination); \Nexus\Helpers\RestoreHelper::restoreTopicToSection($trashedTopic, $destinationSection); $redirect = action('Nexus\\SectionController@show', ['id' => $destinationSection->id]); return redirect($redirect); }