public function actionEditGroup($id) { $model = ForumUserGroup::findByPk($id); if (!UserAccess::get()->isSectionAdmin($model->section_id)) { Messages::get()->error("Not enough rights to edit this user group!"); $this->goBack(); die; } $model->section_id = $this->sectionId; if (isset($_POST['ForumUserGroup'])) { $model->setAttributes($_POST['ForumUserGroup']); if ($model->save()) { Messages::get()->success("Group saved!"); $this->goToAction('groups'); } } $this->setPageLayout('group'); $this->assign('model', $model); }
/** * Set a different default group for current section. It will check if group exists and if it's assigned to this * section but it will not check if user has access to this section as this method will also be used by automated * processes when a new section is generated. * @param int $groupId * @param string $for * @return bool */ public function setDefaultGroup($groupId, $for = 'visitor') { $group = ForumUserGroup::findByPk($groupId); if (!$group) { Messages::get()->error("Group not found!"); return false; } if ($group->section_id != $this->id) { Messages::get()->error("Group is assigned to a different section of the forum!"); return false; } if ('visitor' == $for) { $this->default_visitors_group_id = $groupId; } else { $this->default_members_group_id = $groupId; } return $this->save(); }
/** * @param int $sectionId * @param int $categoryId * @return bool */ public function canRead($sectionId, $categoryId = null) { if ($this->isSiteAdmin() || $this->isSiteModerator()) { return true; } if ($this->isBanned($sectionId)) { return false; // can't read if it's banned } if (isset($this->user2Sections[$sectionId])) { $groupId = $this->user2Sections[$sectionId]['group_id']; if (is_null($categoryId)) { return (bool) $this->user2Sections[$sectionId]['groupRights']['canread']; } } else { if (!isset($this->sections[$sectionId])) { $this->sections[$sectionId] = ForumSection::findByPk($sectionId); } if (!isset($this->sections[$sectionId])) { return false; // section doesn't exists } $groupId = $this->sections[$sectionId]->default_visitors_group_id; } if (is_null($categoryId)) { return (bool) ForumUserGroup::findByPk($groupId)->canread; } $categoryRights = ForumUserGroup::getDb()->table('forum_groups2categories')->where("group_id = :id AND category_id = :cat")->setParams([':id' => $groupId, ':cat' => $categoryId])->first(); if (!$categoryRights) { return (bool) ForumUserGroup::findByPk($groupId)->canread; } return (bool) $categoryRights['canread']; }