public function testRoleModification() { $role = new Role(Role::ADMINISTRATOR); $this->assertTrue($role->hasPerm(Permission::PUBLISH_NEWS)); $this->assertFalse($this->player->hasPermission(Permission::PUBLISH_NEWS)); $this->player->addRole($role); $this->assertTrue($this->player->hasPermission(Permission::PUBLISH_NEWS)); }
public function wipeAction(Player $me) { $wipeable = array('Ban', 'Map', 'Match', 'News', 'NewsCategory', 'Page', 'Server', 'Team'); $models = array(); foreach ($wipeable as $type) { if (!$me->hasPermission($type::HARD_DELETE_PERMISSION)) { continue; } $models = array_merge($models, $type::getQueryBuilder()->where('status')->equals('deleted')->getModels()); } return array('models' => $models); }
public function showAction(Player $player, Player $me, Request $request) { if ($me->hasPermission(Permission::VIEW_VISITOR_LOG)) { $this->creator = new FormCreator($player); $form = $this->creator->create()->handleRequest($request); if ($form->isValid()) { $form = $this->handleAdminNotesForm($form, $player, $me); } $formView = $form->createView(); } else { // Don't spend time rendering the form unless we need it $formView = null; } return array("player" => $player, "adminNotesForm" => $formView); }
public function playerByBzidAction(Player $me, Request $request, FlashBag $flashBag, $bzid = null) { if (!$me->hasPermission(Permission::VIEW_VISITOR_LOG)) { throw new ForbiddenException(); } if ($bzid === null) { if (!$request->query->has('bzid')) { throw new BadRequestException("Please provide the BZID to search for"); } $bzid = $request->query->get('bzid'); } $player = Player::getFromBZID($bzid); if (!$player->isValid()) { $flashBag->add('error', "Player with BZID {$bzid} not found"); return $this->goBack(); } return new RedirectResponse($player->getURL()); }
public function addPlayer(Player $player) { if (count($this->players) >= $this->maxPlayers) { if ($player->hasPermission("sg.perks.join-full")) { // Players who have the correct permissions can join even when arenas are full. $m = count($this->players); $kick = array_keys($this->players)[rand(0, $m - 1)]; $this->kickPlayer($this->players[$kick]["obj"], "Making space for " . $player->getName()); } else { return false; } } $this->players[$player->getName()]["obj"] = $player; $this->players[$player->getName()]["pos"] = new Vector3($player->getX(), $player->getY(), $player->getZ()); $this->players[$player->getName()]["level"] = $player->getLevel(); $this->players[$player->getName()]["inventory"] = $player->getInventory(); return true; }
/** * Make sure that Models invisible to a player are not returned * * Note that this method does not take PermissionModel::canBeSeenBy() into * consideration for performance purposes, so you will have to override this * in your query builder if necessary. * * @param Player $player The player in question * @param bool $showDeleted false to hide deleted models even from admins * @return self */ public function visibleTo($player, $showDeleted = false) { $type = $this->type; if (is_subclass_of($type, "PermissionModel") && $player->hasPermission($type::EDIT_PERMISSION)) { // The player is an admin who can see hidden models if ($showDeleted) { return $this; } else { return $this->where('status')->notEquals('deleted'); } } else { return $this->active(); } }
/** * Sends a message to a group * * @throws HTTPException Thrown if the user doesn't have the * SEND_PRIVATE_MSG permission * @param Player $from The sender * @param Group $to The group that will receive the message * @param Form $form The message's form * @param Form $form The form before it handled the request * @param Form $cloned * @return void */ private function sendMessage(Player $from, Group $to, &$form, $cloned) { if (!$from->hasPermission(Permission::SEND_PRIVATE_MSG)) { throw new ForbiddenException("You are not allowed to send messages"); } $message = $form->get('message')->getData(); $message = $to->sendMessage($from, $message); $this->getFlashBag()->add('success', "Your message was sent successfully"); // Let javascript know the message's ID $this->attributes->set('id', $message->getId()); // Reset the form $form = $cloned; // Notify everyone that we sent a new message $event = new NewMessageEvent($message, false); $this->dispatch(Events::MESSAGE_NEW, $event); }
/** * Find out whether a player can delete this model * * If possible, prefer to override PermissionModel::HARD_DELETE_PERMISSION * * @param Player $player * @return boolean */ public function canBeHardDeletedBy($player) { return $player->hasPermission(static::HARD_DELETE_PERMISSION); }
/** * Add a new news article * * @param string $subject The subject of the article * @param string $content The content of the article * @param int $authorID The ID of the author * @param int $categoryId The ID of the category this article will be published under * @param string $status The status of the article: 'published', 'disabled', or 'deleted' * * @internal param int $categoryID The ID of the category * @return News|bool An object representing the article that was just created or false if the article was not created */ public static function addNews($subject, $content, $authorID, $categoryId = 1, $status = 'published') { $author = new Player($authorID); // Only allow real players to post news articles and if the player posting has permissions to create new posts if ($author->isValid() && $author->hasPermission(Permission::PUBLISH_NEWS)) { return self::create(array('category' => $categoryId, 'subject' => $subject, 'content' => $content, 'author' => $authorID, 'editor' => $authorID, 'status' => $status), 'issiis', array('created', 'updated')); } return false; }