本文整理匯總了PHP中Group::getByName方法的典型用法代碼示例。如果您正苦於以下問題:PHP Group::getByName方法的具體用法?PHP Group::getByName怎麽用?PHP Group::getByName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Group
的用法示例。
在下文中一共展示了Group::getByName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
SecurityTestHelper::createSuperAdmin();
AllPermissionsOptimizationUtil::rebuild();
$everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
$everyoneGroup->save();
$super = User::getByUsername('super');
//Steven have access to missions module
$steven = UserTestHelper::createBasicUser('steven');
$steven->setRight('MissionsModule', MissionsModule::RIGHT_ACCESS_MISSIONS);
$steven->save();
//Jack dont have acess to missions module
$jack = UserTestHelper::createBasicUser('jack');
$mission = new Mission();
$mission->owner = $super;
$mission->takenByUser = $steven;
$mission->description = 'My test description';
$mission->reward = 'My test reward';
$mission->status = Mission::STATUS_AVAILABLE;
$mission->addPermissions($everyoneGroup, Permission::READ_WRITE);
assert($mission->save());
// Not Coding Standard
AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($mission, $everyoneGroup);
}
示例2: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
SecurityTestHelper::createSuperAdmin();
UserTestHelper::createBasicUser('billy');
UserTestHelper::createBasicUser('jane');
$someoneSuper = UserTestHelper::createBasicUser('someoneSuper');
$group = Group::getByName('Super Administrators');
$group->users->add($someoneSuper);
$saved = $group->save();
assert($saved);
// Not Coding Standard
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
SendGrid::register_autoloader();
Smtpapi::register_autoloader();
if (SendGridTestHelper::isSetSendGridAccountTestConfiguration()) {
Yii::app()->sendGridEmailHelper->apiUsername = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiUsername'];
Yii::app()->sendGridEmailHelper->apiPassword = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiPassword'];
Yii::app()->sendGridEmailHelper->setApiSettings();
Yii::app()->sendGridEmailHelper->init();
static::$testEmailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress'];
}
// Delete item from jobQueue, that is created when new user is created
Yii::app()->jobQueue->deleteAll();
}
示例3: makeBuilderPredefinedEmailTemplate
protected function makeBuilderPredefinedEmailTemplate($name, $unserializedData, $subject = null, $modelClassName = null, $language = null, $type = null, $isDraft = 0, $textContent = null, $htmlContent = null)
{
$emailTemplate = new EmailTemplate();
$emailTemplate->type = $type;
//EmailTemplate::TYPE_WORKFLOW;
$emailTemplate->builtType = EmailTemplate::BUILT_TYPE_BUILDER_TEMPLATE;
$emailTemplate->isDraft = $isDraft;
$emailTemplate->modelClassName = $modelClassName;
$emailTemplate->name = $name;
if (empty($subject)) {
$subject = $name;
}
$emailTemplate->subject = $subject;
if (!isset($language)) {
$language = Yii::app()->languageHelper->getForCurrentUser();
}
$emailTemplate->language = $language;
$emailTemplate->htmlContent = $htmlContent;
$emailTemplate->textContent = $textContent;
$emailTemplate->serializedData = CJSON::encode($unserializedData);
$emailTemplate->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
$saved = $emailTemplate->save(false);
if (!$saved) {
throw new FailedToSaveModelException();
}
$emailTemplate = EmailTemplate::getById($emailTemplate->id);
ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($emailTemplate, Group::getByName(Group::EVERYONE_GROUP_NAME));
$saved = $emailTemplate->save(false);
assert('$saved');
}
示例4: run
/**
* Execute the action.
* @param array command line parameters specific for this command
*/
public function run($args)
{
set_time_limit(600);
if (!isset($args[0])) {
$this->usageError('A username must be specified.');
}
try {
Yii::app()->user->userModel = User::getByUsername($args[0]);
} catch (NotFoundException $e) {
$this->usageError('The specified username does not exist.');
}
$group = Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME);
if (!$group->users->contains(Yii::app()->user->userModel)) {
$this->usageError('The specified user is not a super administrator.');
}
if (!isset($args[1])) {
$this->usageError('You must specify an action.');
} else {
$action = $args[1];
}
try {
if ($action == 'saveAllMetadata') {
$this->saveAllMetadata();
} elseif ($action == 'getAllMetadata') {
$this->getAllMetadata();
} else {
$this->usageError('Invalid step/action. Valid values are "saveAllMetadata" and "getAllMetadata".');
}
} catch (Exception $e) {
echo Zurmo::t('Commands', 'An error occur during metadata manage: {message}', array('{message}' => $e->getMessage()));
}
}
示例5: attemptAuthentication
protected function attemptAuthentication()
{
$user = parent::attemptAuthentication();
$userInfo = \UserInfo::getByID($user->getUserID());
$extractor = $this->getExtractor();
$roles = $extractor->getExtra('roles');
// sync groups with roles
if (is_array($roles)) {
$groupIds = array();
foreach ($roles as $role) {
$roleApplicationCode = $role['role_application']['application_code'];
if ($roleApplicationCode == \Config::get('auth.worldskills.roles_application_code')) {
$roleName = $role['name'];
// check for entity role and append entity name
if (isset($role['ws_entity'])) {
$roleName = $roleName . ' - ' . $role['ws_entity']['name']['text'];
}
// check if group exists
$group = \Group::getByName($roleName);
if (!is_object($group)) {
// add missing groups
$group = \Group::add($roleName, '');
}
$groupIds[] = $group->getGroupID();
}
}
// remove duplicate groups
$groupIds = array_unique($groupIds);
// update groups of user
$userInfo->updateGroups($groupIds);
}
// login user again to make sure groups are reloaded
return \User::loginByUserID($user->getUserID());
}
示例6: testPasswordExpiresPolicyRules
public function testPasswordExpiresPolicyRules()
{
$everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
$everyoneGroup->save();
$user = UserTestHelper::createBasicUser('Bobby');
$id = $user->id;
unset($user);
$user = User::getById($id);
$adapter = new UserGroupMembershipToViewAdapter($user);
$viewData = $adapter->getViewData();
$compareData = array($everyoneGroup->id => array('displayName' => 'Everyone', 'canRemoveFrom' => false));
$this->assertEquals($compareData, $viewData);
$a = new Group();
$a->name = 'AAA';
$this->assertTrue($a->save());
$a->users->add($user);
$this->assertTrue($a->save());
$user->forget();
$groupId = $a->id;
$a->forget();
unset($a);
$user = User::getById($id);
$adapter = new UserGroupMembershipToViewAdapter($user);
$viewData = $adapter->getViewData();
$compareData = array($everyoneGroup->id => array('displayName' => 'Everyone', 'canRemoveFrom' => false), $groupId => array('displayName' => 'AAA', 'canRemoveFrom' => true));
$this->assertEquals($compareData, $viewData);
$user->forget();
unset($user);
}
示例7: resolveValueAndSetToModel
/**
* Utilized to create or update model attribute values after a workflow's triggers are fired as true.
* Currently only works with creating new and creating new related models. Not designed to support updating
* existing models.
* @param WorkflowActionProcessingModelAdapter $adapter
* @param $attribute
* @throws FailedToResolveExplicitReadWriteModelPermissionsException
* @throws NotSupportedException
*/
public function resolveValueAndSetToModel(WorkflowActionProcessingModelAdapter $adapter, $attribute)
{
assert('is_string($attribute)');
if ($adapter->getModel()->id < 0) {
throw new NotSupportedException();
}
if ($this->type == self::TYPE_DYNAMIC_SAME_AS_TRIGGERED_MODEL) {
$triggeredModel = $adapter->getTriggeredModel();
if (null == ($explicitReadWriteModelPermissions = $triggeredModel->getExplicitReadWriteModelPermissionsForWorkflow())) {
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($adapter->getTriggeredModel());
}
} elseif ($this->type == self::TYPE_DYNAMIC_OWNER) {
//Do nothing, by default this will take.
return;
} elseif ($this->type == self::TYPE_DYNAMIC_EVERYONE_GROUP) {
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($adapter->getModel());
$explicitReadWriteModelPermissions->addReadWritePermitable(Group::getByName(Group::EVERYONE_GROUP_NAME));
} else {
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($adapter->getModel());
try {
$group = Group::getById((int) $this->type);
$explicitReadWriteModelPermissions->addReadWritePermitable($group);
} catch (NotFoundException $e) {
//todo: handle exception better
return;
}
}
$success = ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($adapter->getModel(), $explicitReadWriteModelPermissions);
if (!$success) {
throw new FailedToResolveExplicitReadWriteModelPermissionsException();
}
}
開發者ID:RamaKavanan,項目名稱:InitialVersion,代碼行數:41,代碼來源:ExplicitReadWriteModelPermissionsWorkflowActionAttributeForm.php
示例8: testCreateAndGetMissionById
public function testCreateAndGetMissionById()
{
$super = User::getByUsername('super');
$fileModel = ZurmoTestHelper::createFileModel();
$steven = UserTestHelper::createBasicUser('steven');
$dueStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 10000);
$mission = new Mission();
$mission->owner = $super;
$mission->takenByUser = $steven;
$mission->dueDateTime = $dueStamp;
$mission->description = 'My test description';
$mission->reward = 'My test reward';
$mission->status = Mission::STATUS_AVAILABLE;
$mission->files->add($fileModel);
$mission->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE);
$this->assertTrue($mission->save());
$id = $mission->id;
$mission->forget();
unset($mission);
$mission = Mission::getById($id);
$this->assertEquals('My test description', $mission->description);
$this->assertEquals('My test reward', $mission->reward);
$this->assertEquals(Mission::STATUS_AVAILABLE, $mission->status);
$this->assertEquals($super, $mission->owner);
$this->assertEquals($steven, $mission->takenByUser);
$this->assertEquals(1, $mission->files->count());
$this->assertEquals($fileModel, $mission->files->offsetGet(0));
$this->assertEquals($dueStamp, $mission->dueDateTime);
$this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $super));
$this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $steven));
}
示例9: makeAll
public function makeAll(&$demoDataHelper)
{
assert('$demoDataHelper instanceof DemoDataHelper');
assert('$demoDataHelper->isSetRange("User")');
$missions = array();
foreach (self::getMissionData() as $randomMissionData) {
$postData = array();
$mission = new Mission();
$mission->setScenario('importModel');
$mission->status = Mission::STATUS_AVAILABLE;
$mission->owner = $demoDataHelper->getRandomByModelName('User');
$mission->createdByUser = $mission->owner;
$mission->description = $randomMissionData['description'];
$mission->reward = $randomMissionData['reward'];
//Add some comments
foreach ($randomMissionData['comments'] as $commentDescription) {
$comment = new Comment();
$comment->setScenario('importModel');
$comment->createdByUser = $demoDataHelper->getRandomByModelName('User');
$comment->description = $commentDescription;
$mission->comments->add($comment);
}
$mission->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE);
$saved = $mission->save();
assert('$saved');
$mission = Mission::getById($mission->id);
ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($mission, Group::getByName(Group::EVERYONE_GROUP_NAME));
$mission->save();
$missions[] = $mission->id;
}
$demoDataHelper->setRangeByModelName('Mission', $missions[0], $missions[count($missions) - 1]);
}
示例10: run
/**
* Execute the action.
* @param array command line parameters specific for this command
*/
public function run($args)
{
set_time_limit('900');
if (!isset($args[0])) {
$this->usageError('A username must be specified.');
}
try {
Yii::app()->user->userModel = User::getByUsername($args[0]);
} catch (NotFoundException $e) {
$this->usageError('The specified username does not exist.');
}
$group = Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME);
if (!$group->users->contains(Yii::app()->user->userModel)) {
$this->usageError('The specified user is not a super administrator.');
}
$startTime = microtime(true);
$template = "{message}\n";
$messageStreamer = new MessageStreamer($template);
$messageStreamer->setExtraRenderBytes(0);
$messageStreamer->add(Zurmo::t('Commands', 'Starting schema update process.'));
$messageLogger = new MessageLogger($messageStreamer);
InstallUtil::runAutoBuildFromUpdateSchemaCommand($messageLogger);
$messageStreamer->add(Zurmo::t('Commands', 'Autobuild complete, rebuilding read permissions.'));
if (SHOW_QUERY_DATA) {
$messageStreamer->add(PageView::getTotalAndDuplicateQueryCountContent());
}
ReadPermissionsOptimizationUtil::rebuild();
$messageStreamer->add(Zurmo::t('Commands', 'Rebuild read permissions complete.'));
$endTime = microtime(true);
$messageStreamer->add(Zurmo::t('Commands', 'Schema update complete.'));
$messageStreamer->add(Zurmo::t('Commands', 'Total run time: {formattedTime} seconds.', array('{formattedTime}' => number_format($endTime - $startTime, 3))));
if (SHOW_QUERY_DATA) {
$messageStreamer->add(PageView::getTotalAndDuplicateQueryCountContent());
}
}
示例11: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
SecurityTestHelper::createSuperAdmin();
self::$emailHelperSendEmailThroughTransport = Yii::app()->emailHelper->sendEmailThroughTransport;
UserTestHelper::createBasicUser('billy');
UserTestHelper::createBasicUser('jane');
$someoneSuper = UserTestHelper::createBasicUser('someoneSuper');
$group = Group::getByName('Super Administrators');
$group->users->add($someoneSuper);
$saved = $group->save();
assert($saved);
// Not Coding Standard
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
if (EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
$steve = UserTestHelper::createBasicUser('steve');
EmailMessageTestHelper::createEmailAccount($steve);
Yii::app()->imap->imapHost = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapHost'];
Yii::app()->imap->imapUsername = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapUsername'];
Yii::app()->imap->imapPassword = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapPassword'];
Yii::app()->imap->imapPort = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapPort'];
Yii::app()->imap->imapSSL = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapSSL'];
Yii::app()->imap->imapFolder = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapFolder'];
Yii::app()->imap->setInboundSettings();
Yii::app()->imap->init();
self::loadEmailHelperWithTestCredentials();
}
// Delete item from jobQueue, that is created when new user is created
Yii::app()->jobQueue->deleteAll();
}
示例12: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
SecurityTestHelper::createSuperAdmin();
self::$emailHelperSendEmailThroughTransport = Yii::app()->emailHelper->sendEmailThroughTransport;
static::$userpsg = UserTestHelper::createBasicUser('userpsg');
static::$usercstmsmtp = UserTestHelper::createBasicUser('usercstmsmtp');
static::$basicuser = UserTestHelper::createBasicUser('basicuser');
static::$bothSGandCstmUser = UserTestHelper::createBasicUser('bothSGandCstmUser');
$someoneSuper = UserTestHelper::createBasicUser('someoneSuper');
$group = Group::getByName('Super Administrators');
$group->users->add($someoneSuper);
$saved = $group->save();
assert($saved);
// Not Coding Standard
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
if (EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
EmailMessageTestHelper::createEmailAccountForMailerFactory(static::$usercstmsmtp);
EmailMessageTestHelper::createEmailAccountForMailerFactory(static::$bothSGandCstmUser);
}
SendGrid::register_autoloader();
Smtpapi::register_autoloader();
if (SendGridTestHelper::isSetSendGridAccountTestConfiguration()) {
SendGridTestHelper::createSendGridEmailAccount(static::$userpsg);
SendGridTestHelper::createSendGridEmailAccount(static::$bothSGandCstmUser);
Yii::app()->sendGridEmailHelper->apiUsername = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiUsername'];
Yii::app()->sendGridEmailHelper->apiPassword = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiPassword'];
Yii::app()->sendGridEmailHelper->setApiSettings();
Yii::app()->sendGridEmailHelper->init();
}
// Delete item from jobQueue, that is created when new user is created
Yii::app()->jobQueue->deleteAll();
}
示例13: setup1
public function setup1()
{
Yii::app()->user->userModel = User::getByUsername('super');
$accounts = Account::getAll();
assert('count($accounts) == 3');
// Not Coding Standard
// The following is the test set up, given the
// users, groups, and roles set up by SecurityTestHelper
// the the additional setup below.
// There is an account, owned by Benny, to which
// Betty has been given explicit access, along
// with anyone in Support Staff. The support staff
// are Bernice and Brian. Benny is a Sales Person
// so Bobby, the Sales Manager has access via roles.
// Billy the admin guy has no access.
$accounts[0]->owner = User::getByUsername('benny');
$accounts[0]->addPermissions(User::getByUsername('betty'), Permission::READ);
$accounts[0]->addPermissions(Group::getByName('Support Staff'), Permission::READ);
$saved = $accounts[0]->save();
assert('count($saved)');
// Not Coding Standard
ReadPermissionsOptimizationUtil::rebuild();
$this->assertEquals(5, self::getAccountMungeRowCount());
$this->rebuildAndTestThatTheMungeDoesntChange();
}
示例14: update_group
public function update_group() {
$g = Group::getByID(intval($_REQUEST['gID']));
$txt = Loader::helper('text');
$valt = Loader::helper('validation/token');
$gName = $txt->sanitize($_POST['gName']);
$gDescription = $_POST['gDescription'];
if (!$gName) {
$this->error->add(t("Name required."));
}
if (!$valt->validate('add_or_update_group')) {
$this->error->add($valt->getErrorMessage());
}
$g1 = Group::getByName($gName);
if ($g1 instanceof Group) {
if ((!is_object($g)) || $g->getGroupID() != $g1->getGroupID()) {
$this->error->add(t('A group named "%s" already exists', $g1->getGroupName()));
}
}
if (count($error) == 0) {
$g->update($gName, $_POST['gDescription']);
$cnta = Loader::controller('/dashboard/users/add_group');
$cnta->checkExpirationOptions($g);
$this->redirect('/dashboard/users/groups', 'group_updated');
}
}
示例15: run
/**
* Execute the action.
* @param array command line parameters specific for this command
*/
public function run($args)
{
set_time_limit('900');
if (!isset($args[0])) {
$this->usageError('A username must be specified.');
}
try {
Yii::app()->user->userModel = User::getByUsername($args[0]);
} catch (NotFoundException $e) {
$this->usageError('The specified username does not exist.');
}
$group = Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME);
if (!$group->users->contains(Yii::app()->user->userModel)) {
$this->usageError('The specified user is not a super administrator.');
}
if (User::getRootUserCount() > 0) {
echo 'There is already a root user. A new one cannot be specified.';
Yii::app()->end();
}
Yii::app()->user->userModel->setIsRootUser();
Yii::app()->user->userModel->hideFromSelecting = true;
Yii::app()->user->userModel->hideFromLeaderboard = true;
$saved = Yii::app()->user->userModel->save();
if (!$saved) {
throw new FailedToSaveModelException();
}
$template = "{message}\n";
$messageStreamer = new MessageStreamer($template);
$messageStreamer->setExtraRenderBytes(0);
$messageStreamer->add('');
$messageStreamer->add(Zurmo::t('Commands', 'User with username {username} elevated to root.', array('{username}' => Yii::app()->user->userModel->username)));
}