public function setUp()
 {
     parent::setUp();
     $this->role = Role::getNewInstance('__testrole__');
     $this->role->save();
     $this->userGroup = UserGroup::getNewInstance('Any random group name');
     $this->userGroup->save();
 }
Пример #2
0
 public function addAction()
 {
     $ans = [];
     try {
         if (!$this->request->isPost()) {
             throw new Exception('请用正确的方式访问我们的API', 99);
         }
         $validation = new Phalcon\Validation();
         $validation->add('name', new PresenceOf(['message' => 'name is needed']));
         $validation->add('name', new StringLength(['max' => 30, 'messageMaximum' => 'The name is too long.']));
         $messages = $validation->validate($_POST);
         foreach ($messages as $message) {
             throw new Exception($message, 102);
         }
         //获取Post中的内容,然后将name存入到数据库中
         $name = $this->request->getPost('name');
         $userGroup = new UserGroup();
         $userGroup->name = $name;
         $success = $userGroup->save();
         if ($success) {
             $ans['id'] = $userGroup->id;
         } else {
             foreach ($userGroup->getMessages() as $message) {
                 throw new Exception($message, 100);
             }
         }
     } catch (Exception $e) {
         $ans['id'] = -1;
         Utils::makeError($e, $ans);
     } finally {
         echo json_encode($ans);
     }
 }
Пример #3
0
/**
 * Save imported class data to database
 *
 * @param $classes
 *
 * @return int
 */
function save_data($classes)
{
    $count = 0;
    $usergroup = new UserGroup();
    foreach ($classes as $index => $class) {
        $usersToAdd = isset($class['users']) ? $class['users'] : null;
        unset($class['users']);
        $id = $usergroup->save($class);
        if ($id) {
            if (!empty($usersToAdd)) {
                $usersToAddList = explode(',', $usersToAdd);
                $userIdList = array();
                foreach ($usersToAddList as $username) {
                    $userInfo = api_get_user_info_from_username($username);
                    $userIdList[] = $userInfo['user_id'];
                }
                if (!empty($userIdList)) {
                    $usergroup->subscribe_users_to_usergroup($id, $userIdList, false);
                }
            }
            $count++;
        }
    }
    return $count;
}
Пример #4
0
 public function testCreateNewGroup()
 {
     // Create new UserGroup model
     $model = new UserGroup();
     $model->name = 'Admin';
     $model->description = 'Test Group';
     $model->gperm_access_admin_panel = 1;
     $model->pperm_browse_crash_reports = 1;
     $model->pperm_browse_bugs = 1;
     $model->pperm_browse_debug_info = 1;
     $model->pperm_manage_crash_reports = 1;
     $model->pperm_manage_bugs = 1;
     $model->pperm_manage_debug_info = 1;
     $model->default_sidebar_tab = 'Digest';
     $model->default_bug_status_filter = 'open';
     // Validate model - assume failure (group name already exist)
     $this->assertFalse($model->validate());
     // Correct name
     $model->name = 'NewGroup';
     // Validate model - assume success
     $this->assertTrue($model->validate());
     // Apply changes to database - assume success
     $this->assertTrue($model->save());
     // Ensure group's status is Active
     $this->assertTrue($model->status == UserGroup::STATUS_ACTIVE);
     // Check the new group is not standard
     $this->assertFalse($model->isStandard());
     // Check the new group can be updated
     $this->assertTrue($model->canUpdate());
     // Delete new group - should succeed
     $this->assertTrue($model->delete());
 }
Пример #5
0
 public function groups($nickname = null)
 {
     $user = $this->load_user($nickname);
     $this->assign("user", $user);
     if ($this->post && isset($_POST['group_id'])) {
         $group = Group::find_by_iD($_POST['group_id']);
         if ($group) {
             $userGroup = new UserGroup();
             $userGroup->group_id = $group->id;
             $userGroup->user_id = $user->id;
             if ($userGroup->save()) {
                 Site::Flash('notice', 'The user has been added to the group');
                 Redirect("admin/users/" . $user->permalink() . '/groups');
             }
         }
     }
     $userGroups = array();
     foreach ($user->groups() as $ug) {
         $userGroups[] = $ug->id;
     }
     $allGroups = Group::find_all();
     $groups = array();
     foreach ($allGroups as $group) {
         if (in_array($group->id, $userGroups)) {
             continue;
         }
         $groups[$group->id] = $group->name;
     }
     $this->assign('groups', $groups);
     $this->title = "{$user->nickname} :: Groups";
     $this->render("user/groups.tpl");
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     if ($this->user_role == 'top_admin') {
         $model = new UserGroup();
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         $criteria = new CDbCriteria();
         $criteria->condition = 'status=:status';
         $criteria->params = array(':status' => 1);
         $criteria->order = 'sort_order';
         $menu_list = UserMenu::model()->findAll($criteria);
         if (isset($_POST['UserGroup'])) {
             $sep = "";
             $user_menu = "";
             if (isset($_POST['user_menu'])) {
                 // echo "<pre>".print_r($_POST['user_menu'])."</pre>";
                 $count_menu = count($_POST['user_menu']);
                 $menu_list = array();
                 $menu_list = $_POST['user_menu'];
                 foreach ($menu_list as $key => $value) {
                     $user_menu .= $sep . $value;
                     $sep = ",";
                 }
             }
             $_POST['UserGroup']['user_menu'] = $user_menu;
             $model->attributes = $_POST['UserGroup'];
             if ($model->save()) {
                 $this->redirect(array('index'));
             }
         }
         $this->render('create', array('model' => $model, 'menu_list' => $menu_list));
     } else {
         $this->redirect(array('site/index'));
     }
 }
 public function group_store()
 {
     $data = Input::all();
     $group = new UserGroup();
     $group->fill($data);
     $group->save();
     return Redirect::route('perm.group.list');
 }
Пример #8
0
function addUserGroupSubmit($p)
{
    $grp = new UserGroup();
    $grp->setName($p['name']);
    $grp->setInfo($p['info']);
    $grp->setLevel($p['level']);
    $grp->save();
    redir('a/usergroups');
}
Пример #9
0
function saveUserGroupSubmit($p)
{
    $grp = new UserGroup($p['g_id']);
    $grp->setName($p['name']);
    $grp->setInfo($p['info']);
    $grp->setLevel($p['level']);
    $grp->save();
    return true;
}
Пример #10
0
 /**
  * add user to groups
  *
  * @param array $group_name
  */
 public function addToGroups($group_name)
 {
     $group_ids = Group::findGroupIdByNames($group_name);
     foreach ($group_ids as $group_id) {
         $user_group = new UserGroup();
         $user_group->user_id = $this->getId();
         $user_group->group_id = $group_id;
         $user_group->save();
     }
 }
Пример #11
0
 /**
  * We're going to create a UserGroup when a new Model record is created
  *
  * @param Model $Model
  * @param boolean $created
  */
 private function _mainModelAfterSave(Model $Model, $created)
 {
     if ($created) {
         $UserGroup = new UserGroup();
         // create a UserGroup for this Course
         $data = $UserGroup->create(array('title' => $Model->data[$Model->alias][$Model->displayField], 'model' => $Model->alias, 'foreign_key' => $Model->id, 'owner_id' => $Model->userId));
         $UserGroup->save($data);
         // make the current Auth.User a member, and the moderator, for this group
         $UserGroup->UsersUserGroup->add(array('UsersUserGroup' => array('user_id' => $Model->userId, 'user_group_id' => $UserGroup->id, 'is_moderator' => 1, 'is_approved' => 1)));
     }
 }
Пример #12
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new UserGroup();
     if (isset($_POST['UserGroup'])) {
         $model->attributes = $_POST['UserGroup'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #13
0
/**
 * Save imported class data to database
 */
function save_data($classes)
{
    $number_of_added_classes = 0;
    $usergroup = new UserGroup();
    foreach ($classes as $index => $class) {
        $id = $usergroup->save($class);
        if ($id) {
            $number_of_added_classes++;
        }
    }
    return $number_of_added_classes;
}
Пример #14
0
 public function run()
 {
     $model = new UserGroup();
     if (isset($_POST['UserGroup'])) {
         $model->attributes = $_POST['UserGroup'];
         $model->acl = isset($_POST['acls']) ? $_POST['acls'] : array();
         if ($model->save()) {
             $this->controller->message('success', Yii::t('admin', 'Add Success'), $this->controller->createUrl('index'));
         }
     }
     $this->controller->render('create', array('model' => $model, 'acls' => $this->controller->acl()));
 }
Пример #15
0
 /**
  * 保存用户到用户组
  */
 static function UserGroupSave($user_id, $group)
 {
     \Yii::app()->db->createCommand()->update('users', array('yourself' => $_POST['self'] ? 1 : 0), 'id=:id', array('id' => $user_id));
     if ($group) {
         UserGroup::model()->deleteAllByAttributes(array('user_id' => $user_id));
         foreach ($group as $group_id) {
             $model = new UserGroup();
             $model->group_id = $group_id;
             $model->user_id = $user_id;
             $model->save();
         }
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new UserGroup();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['UserGroup'])) {
         $model->attributes = $_POST['UserGroup'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->GroupID));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #17
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new UserGroup();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['UserGroup'])) {
         $model->attributes = $_POST['UserGroup'];
         if ($model->save()) {
             Yii::app()->user->setFlash('success', 'Saved successfully');
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #18
0
	public function testGroup()
	{
		$group = new UserGroup('Webmasters');
		$group->save();
		$group->grant('someGrant');
		
		$this->assertFalse(Acl::isAllowed('dvorak', 'someGrant'));
		$group->add('dvorak');
		$this->assertTrue(Acl::isAllowed('dvorak', 'someGrant'));
		
		$group = new UserGroup('BadGroup');
		$group->save();
		$group->revoke('someGrant');
		$group->add('dvorak');
		
		$this->assertTrue(Acl::isAllowed('dvorak', 'someGrant')); // Even if dvorak is in a group that has no right he is allowed
	}
Пример #19
0
 function executeSave()
 {
     $request = fvRequest::getInstance();
     if (!($UserGroup = UserGroupManager::getInstance()->getByPk($request->getRequestParameter('id')))) {
         $UserGroup = new UserGroup();
     }
     $mg = $request->getRequestParameter('mg');
     if (empty($mg['default_group']) && $UserGroup->default_group) {
         $this->setFlash("Ошибка при сохранении данных проверте правильность введенных данных", self::$FLASH_ERROR);
         if (fvRequest::getInstance()->isXmlHttpRequest()) {
             return self::$FV_AJAX_CALL;
         } else {
             return self::$FV_OK;
         }
     }
     $UserGroup->updateFromRequest($mg);
     if ($UserGroup->save()) {
         if ($UserGroup->default_group) {
             UserGroupManager::getInstance()->massUpdate("id <> " . $UserGroup->getPk(), array('default_group' => 0));
         }
         $this->setFlash("Данные успешно сохранены", self::$FLASH_SUCCESS);
         fvResponce::getInstance()->setHeader('Id', $UserGroup->getPk());
         UserManager::getInstance()->massUpdate(sprintf('group_id = %d AND inherit = 1', $UserGroup->getPk()), array('permitions' => $UserGroup->permitions));
         /*            $Users = UserManager::getInstance()->getAll('group_id = ? AND inherit = 1 AND global_rights = 1', null, null, $UserGroup->getPk());
                     
                     foreach ($Users as $User) {
                         $User->permitions = $UserGroup->permitions;
                         $User->save();
                     }
         */
     } else {
         fvResponce::getInstance()->setHeader('X-JSON', json_encode($UserGroup->getValidationResult()));
         $this->setFlash("Ошибка при сохранении данных проверте правильность введенных данных", self::$FLASH_ERROR);
     }
     if ($request->getRequestParameter('redirect')) {
         fvResponce::getInstance()->setHeader('redirect', fvSite::$fvConfig->get('dir_web_root') . $request->getRequestParameter('module') . "/");
     }
     if (fvRequest::getInstance()->isXmlHttpRequest()) {
         return self::$FV_AJAX_CALL;
     } else {
         return self::$FV_OK;
     }
 }
 public function create($group_id = null)
 {
     $group = self::load_group($group_id);
     if ($this->post) {
         $added = false;
         foreach ($_POST['users'] as $id) {
             $user = User::find_by_id($id);
             if ($user) {
                 $user_group = new UserGroup();
                 $user_group->user_id = $user->id;
                 $user_group->group_id = $group->id;
                 if ($user_group->save()) {
                     $added = true;
                 }
             }
         }
         if ($added) {
             Site::Flash("notice", "The users have been added to the group");
         }
         Redirect("admin/groups/{$group->id}");
     }
     $group_users = array();
     foreach ($group->users() as $user) {
         $group_users[] = $user->id;
     }
     $users = array();
     $all_users = User::find_all("", "nickname ASC");
     foreach ($all_users as $user) {
         if (!in_array($user->id, $group_users)) {
             $users[] = $user;
         }
     }
     if (count($users) == 0) {
         Site::Flash("error", "There are no more users to add.");
         Redirect("admin/groups/{$group->id}");
     }
     $this->assign("users", $users);
     $this->assign("group", $group);
     $this->title = "Add Users";
     $this->render("user_group/create.tpl");
 }
Пример #21
0
/**
 * user_groups スキーマの読み込み
 */
if (!$this->loadSchema('1.6.9', '', 'user_groups')) {
    $this->setMessage('user_groups のテーブル構造の更新に失敗しました。', true);
} else {
    $this->setMessage('user_groups のテーブル構造の更新に成功しました。');
}
/**
 * user_groups テーブル更新
 *
 * 認証プレフィックスの更新
 */
App::import('Model', 'UserGroup');
$UserGroup = new UserGroup();
$datas = $UserGroup->find('all');
$result = true;
if ($datas) {
    foreach ($datas as $data) {
        $data['UserGroup']['auth_prefix'] = 'admin';
        $UserGroup->set($data);
        if (!$UserGroup->save()) {
            $result = false;
        }
    }
}
if ($result) {
    $this->setMessage('user_groups テーブルの更新に成功しました。');
} else {
    $this->setMessage('user_groups テーブルの更新に失敗しました。', true);
}
Пример #22
0
function WSCreateGroup($params)
{
    if (!WSHelperVerifyKey($params['secret_key'])) {
        return return_error(WS_ERROR_SECRET_KEY);
    }
    $userGroup = new UserGroup();
    $params = ['name' => $params['name']];
    return $userGroup->save($params);
    //return GroupPortalManager::add($params['name'], null, null, 1);
}
Пример #23
0
Display::display_introduction_section(get_lang('Classes'));
$usergroup = new UserGroup();
$usergroup->showGroupTypeSetting = true;
// Action handling: Adding a note
if (isset($_GET['action']) && $_GET['action'] == 'add') {
    if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
        api_not_allowed();
    }
    $form = new FormValidator('usergroup', 'post', api_get_self() . '?action=' . Security::remove_XSS($_GET['action']));
    $usergroup->setForm($form, 'add');
    // Setting the defaults
    $form->setDefaults(['visibility' => 2]);
    // The validation or display
    if ($form->validate()) {
        $values = $form->exportValues();
        $res = $usergroup->save($values);
        if ($res) {
            Display::display_confirmation_message(get_lang('ItemAdded'));
        } else {
            Display::display_warning_message(Security::remove_XSS($values['name']) . ': ' . get_lang('AlreadyExists'));
        }
        $usergroup->display();
    } else {
        echo '<div class="actions">';
        echo '<a href="' . api_get_self() . '">' . Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM) . '</a>';
        echo '</div>';
        $token = Security::get_token();
        $form->addElement('hidden', 'sec_token');
        $form->setConstants(array('sec_token' => $token));
        $form->display();
    }
Пример #24
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionUpdate()
 {
     $model = $this->loadModel();
     $profile = $model->profile;
     $gprofile = Profile::model()->with('groups')->findbyPk($model->id);
     $profile->group_id = $gprofile->groups;
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         //$model->attributes=$_POST['User'];
         $model->status = $_POST['User']['status'];
         //$profile->attributes=$_POST['Profile'];
         $profile->branch_id = $_POST['Profile']['branch_id'];
         if ($model->validate() && $profile->validate()) {
             $old_password = User::model()->notsafe()->findByPk($model->id);
             /*if ($old_password->password!=$model->password) {
             			$model->password=PasswordHelper::hashPassword($model->password);
             			$model->activkey=PasswordHelper::hashPassword(microtime().$model->password);
             		}*/
             $model->save();
             $profile->save();
             $criteria = new CDbCriteria();
             $criteria->condition = 'profile_id=:profile_id';
             $criteria->params = array(':profile_id' => $model->id);
             UserGroup::model()->deleteAll($criteria);
             foreach ($_POST['Profile']['group_id'] as $groupid) {
                 $userGroup = new UserGroup();
                 $userGroup->profile_id = $model->id;
                 $userGroup->group_id = $groupid;
                 $userGroup->save();
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('update', array('model' => $model, 'profile' => $profile));
 }
Пример #25
0
if (api_get_setting('allow_social_tool') != 'true') {
    api_not_allowed();
}
if (api_get_setting('allow_students_to_create_groups_in_social') == 'false' && !api_is_allowed_to_edit()) {
    api_not_allowed();
}
$table_message = Database::get_main_table(TABLE_MESSAGE);
$usergroup = new UserGroup();
$form = new FormValidator('add_group');
$usergroup->setGroupType($usergroup::SOCIAL_CLASS);
$usergroup->setForm($form, 'add', array());
if ($form->validate()) {
    $values = $form->exportValues();
    $values['group_type'] = UserGroup::SOCIAL_CLASS;
    $values['relation_type'] = GROUP_USER_PERMISSION_ADMIN;
    $groupId = $usergroup->save($values);
    Display::addFlash(DIsplay::return_message(get_lang('GroupAdded')));
    header('Location: group_view.php?id=' . $groupId);
    exit;
}
$nameTools = get_lang('AddGroup');
$this_section = SECTION_SOCIAL;
$interbreadcrumb[] = array('url' => 'home.php', 'name' => get_lang('Social'));
$interbreadcrumb[] = array('url' => 'groups.php', 'name' => get_lang('Groups'));
$interbreadcrumb[] = array('url' => '#', 'name' => $nameTools);
$social_avatar_block = SocialManager::show_social_avatar_block('group_add');
$social_menu_block = SocialManager::show_social_menu('group_add');
$social_right_content = $form->returnForm();
$tpl = new Template(null);
SocialManager::setSocialUserBlock($tpl, $user_id, null, null);
$tpl->setHelp('Groups');
Пример #26
0
	public function testAddMemberTwice()
	{
		$group = new UserGroup('SomeName');
		$group->save();
		$group->add('dvorak');
		
		try
		{
			$group->add('dvorak');
			$this->fail('Expected exception');
		}
		catch (Exception $e)
		{
			$this->assertEquals('User is already member of group', $e->getMessage());
		}
	}
Пример #27
0
 protected function Int_register($params)
 {
     $mob = $params['mobile'];
     $pwd = $params['password'];
     //注册开始
     $reg_ok = false;
     $notify_msg = '';
     if ($mob && $pwd) {
         //预先验证使用的用户名本店范围内不重复
         $testUser = UsersPassword::model()->find("username='******' and shop_id=0");
         if (!$testUser) {
             //开启事务
             $this->doTransaction('db', 'start');
             //写入用户基本信息
             $userMod = new Users();
             $userMod->attributes = array('shop_id' => 0, 'dis_name' => $mob, 'real_name' => $mob, 'status' => 1, 'create_time' => time());
             if (!($userMod->validate() && $userMod->save())) {
                 $this->doTransaction('db', 'rollback');
                 $notify_msg = 'user-save-error';
             } else {
                 //保存用户组信息
                 $uGroup = new UserGroup();
                 $uGroup->attributes = array('user_id' => $userMod->user_id, 'group_id' => USER_GROUP_GUEST, 'status' => 'enabled');
                 if (!($uGroup->validate() && $uGroup->save())) {
                     $this->doTransaction('db', 'rollback');
                     $notify_msg = 'user-group-save-error';
                 } else {
                     //进一步处理用户登录授权方式
                     $grant_type_id = DEFAULT_GUEST_LOGIN_TYPE;
                     //找到模块信息
                     $gtInfo = LoginGrantTypes::model()->findByPk($grant_type_id);
                     if (!$gtInfo) {
                         $this->doTransaction('db', 'rollback');
                         $notify_msg = 'user-grant-error';
                     } else {
                         $userLoginGrantMod = new UsersLoginGrant();
                         $userLoginGrantMod->attributes = array('user_id' => $userMod->user_id, 'grant_type_id' => $grant_type_id, 'grant_type_name' => $gtInfo->grant_name, 'grantModelClass' => $gtInfo->grantModelClass, 'status' => 1);
                         if (!($userLoginGrantMod->validate() && $userLoginGrantMod->save())) {
                             $this->doTransaction('db', 'rollback');
                             $notify_msg = 'user-grent-save-error';
                         } else {
                             //保存用户密码
                             $rndCode = rand(1000, 9999);
                             $newpass = md5(md5($pwd) . $rndCode);
                             $userPassMod = new UsersPassword();
                             $userPassMod->attributes = array('user_id' => $userMod->user_id, 'shop_id' => 0, 'username' => $mob, 'password' => $newpass, 'rndCode' => $rndCode);
                             if (!($userPassMod->validate() && $userPassMod->save())) {
                                 $this->doTransaction('db', 'rollback');
                                 $notify_msg = 'user-password-save-error';
                             } else {
                                 $this->doTransaction('db', 'commit');
                                 $notify_msg = 'user-created';
                                 $reg_ok = true;
                             }
                         }
                     }
                 }
             }
         } else {
             $notify_msg = 'user-exists';
         }
     }
     return $this->_output(array('message' => $notify_msg, 'token' => !$reg_ok ? '' : $this->_grentAccessTokenForUser($userMod->user_id)), $reg_ok);
 }
Пример #28
0
 /**
  * 用户组添加
  *
  * @param  $id
  */
 public function actionGroupCreate()
 {
     $model = new UserGroup();
     if (isset($_POST['UserGroup'])) {
         $model->attributes = $_POST['UserGroup'];
         $acl = Yii::app()->request->getPost('acls');
         if (is_array($acl)) {
             $model->acl = implode(',', array_unique($acl));
         } else {
             $model->acl = '';
         }
         if ($model->save()) {
             $this->message('success', Yii::t('admin', 'Add Success'), $this->createUrl('group'));
         }
     }
     $this->render('group_create', array('model' => $model, 'acls' => $this->acl()));
 }
Пример #29
0
 public function setUp()
 {
     parent::setUp();
     $this->group = UserGroup::getNewInstance('test', 'test');
     $this->group->save();
 }
Пример #30
0
	protected function insert()
	{
		parent::insert();
		$group = new UserGroup('__'.$this->username);
		$group->save();
		
		$group->add($this->username);
		return $this->lockKey;
	}