Move all the existing users to a new group
776471
def participation_policy_changed(ob, event):
    
    workspace = IWorkspace(ob)
    old_group_name = workspace.group_for_policy(event.old_policy)
    old_group = api.group.get(old_group_name)
    for member in old_group.getAllGroupMembers():
        groups = workspace.get(member.getId()).groups
        groups -= set([event.old_policy.title()])
        groups.add(event.new_policy.title())
444790
public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            if (Schema::hasColumn('users', 'deleted_at') == false) {
                $table->softDeletes();
            }
        });
    }
593380
public function up()
    {
        Schema::create('google_users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('customerId');
            $table->string('kind');
            $table->integer('google_id')->unsigned()->nullable();
            $table->string('etag');
            $table->string('primaryEmail')->unique();
            $table->string('givenName');
            $table->string('familyName');
            $table->string('fullName');
            $table->string('orgUnitPath');
            $table->json('organizations')->nullable();
            $table->boolean('isAdmin');
            $table->boolean('isDelegatedAdmin');
            $table->dateTime('lastLoginTime');
            $table->dateTime('creationTime');
            $table->dateTime('deletionTime')->nullable();
            $table->dateTime('agreedToTerms');
            $table->string('password')->nullable();
            $table->string('hashFunction')->nullable();
            $table->boolean('suspended');
            $table->string('suspensionReason')->nullable();
            $table->boolean('changePasswordAtNextLogin');
            $table->json('emails');
            $table->timestamps();
        });
    }
760143
public function up()
    {
        // Roles: visitantes, administradores, gerentes, etc
        Schema::create('acl_groups', function (Blueprint $table) {

            $table->increments('id');
            $table->string('name', 50);
            $table->string('slug', 50)->unique();
            $table->text('description')->nullable();
            $table->enum('system', ['yes', 'no'])->default('no');
            $table->timestamps();

            $table->softDeletes();
        });

        AclGroup::create([
            'name' => 'Admin',
            'slug' => 'admin',
            'description' => 'Administradores',
            'system' => 'yes',
            ]);

        AclGroup::create([
            'name' => 'Users',
            'slug' => 'users',
            'description' => 'Usuários comuns',
            'system' => 'yes',
            ]);
    }
498246
public function up()
    {
        if ($this->hasTable('users_groups')) {
            return;
        }

        $table = $this->table('users_groups');
        $table->addColumn('user_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])
            ->addColumn('group_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false]);
        $table->addIndex('user_id', ['name' => 'FK_USER_ID', 'unique' => false])
            ->addIndex('group_id', ['name' => 'FK_GROUP_ID', 'unique' => false]);
        $table->create();

        $this->unsignedIntId($table);
        $table->save();

        $UsersGroups = \Cake\ORM\TableRegistry::get('UsersGroups');
        $UsersGroups->save($UsersGroups->newEntity([
            'user_id' => 1,
            'group_id' => 1
        ]));
    }
831678
def cli(ctx, group_id, new_name):
    
    return ctx.gi.groups.update_group(group_id, new_name)
1218949
public function migrate()
	{
		// Set our group arg & call migration
		$this->arguments->setOpt('group', $this->group->get('cn'));
		\App::get('client')->call('migration', 'run', $this->arguments, $this->output);
	}
888822
public function up()
    {
    	if (Schema::hasTable('users')) {

    		Schema::table('users', function (Blueprint $table) {
	            
	            if (!Schema::hasColumn('users', 'is_admin')) {

	            	$table->tinyInteger('is_admin')->default(0)->comment('1: admin, 0: not is admin');
	            }

	            if (!Schema::hasColumn('users', 'name')) {
	            	$table->string('name');
	            }
	            
	            if (!Schema::hasColumn('users', 'email')) {
	            	$table->string('email')->unique();
	            }

	            if (!Schema::hasColumn('users', 'password')) {
	            	$table->string('password');
	            }

	            if (!Schema::hasColumn('users', 'remember_token')) {
	            	$table->rememberToken();
	            }


	        });
    	}

    	else {

    		Schema::create('users', function (Blueprint $table) {
	            $table->increments('id');
	            $table->string('name');
	            $table->string('email')->unique();
	            $table->string('password');
	            $table->tinyInteger('is_admin')->default(0)->comment('1: admin, 0: not is admin');
	            $table->rememberToken();
	            $table->timestamps();
	        });
    	}
        
    }
584342
public function up()
    {
        Schema::create('acl_groups_permissions', function (Blueprint $table) {

            $table->unsignedInteger('role_id')->index();
            $table->foreign('role_id')->references('id')->on('acl_roles')->onDelete('cascade');

            $table->unsignedInteger('group_id')->index();
            $table->foreign('group_id')->references('id')->on('acl_groups')->onDelete('cascade');

            $table->enum('create', ['yes', 'no']);
            $table->enum('read', ['yes', 'no']);
            $table->enum('update', ['yes', 'no']);
            $table->enum('delete', ['yes', 'no']);

            $table->primary(['role_id', 'group_id']);
        });
    }
1107875
public function up()
    {
        $table = $this->table('users');

        if (!$table->hasColumn('firstname')) {
            $table->addColumn('firstname', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'after' => 'language_id']);
        }

        if (!$table->hasColumn('lastname')) {
            $table->addColumn('lastname', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'after' => 'firstname']);
        }

        $table->update();

        $this->clearModelCache();
    }
40038
def _UpdateUserGroups(self, user, groups):
    
    groups = ','.join(groups)
    self.logger.debug('Updating user %s with groups %s.', user, groups)
    command = self.usermod_cmd.format(user=user, groups=groups)
    try:
      subprocess.check_call(command.split(' '))
    except subprocess.CalledProcessError as e:
      self.logger.warning('Could not update user %s. %s.', user, str(e))
      return False
    else:
      self.logger.debug('Updated user account %s.', user)
      return True
1094182
public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('uuid', 36)->unique();
            $table->string('username', 120)->unique();
            $table->string('email_address', 120)->unique();
            $table->string('password', 36);
            $table->string('password_token', 120);
            $table->tinyInteger('status')->default(1)->comment('1 = Active, 2 = Inactive');
            $table->tinyInteger('is_vissible')->default(1)->comment('1 = Visible, 2 = Disable');
            $table->dateTime('last_seen');
            $table->rememberToken();
            $table->timestamps();
            $table->charset = 'utf8';
            $table->collation = 'utf8_general_ci';
        });
    }
603459
def group_remove(groupname,
                 user=None,
                 host=None,
                 port=None,
                 maintenance_db=None,
                 password=None,
                 runas=None):
    '''
    
    '''
    return _role_remove(groupname,
                        user=user,
                        host=host,
                        port=port,
                        maintenance_db=maintenance_db,
                        password=password,
                        runas=runas)
1183544
public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->enum('type', array_values(UserType::toArray()))->default(UserType::__default);
            $table->boolean('is_active')->default(true);
            $table->dateTime('last_login_at')->nullable();
            $table->integer('login_count')->unsigned()->nullable()->default(0);
            $table->softDeletes();
        });
    }
703276
public function up()
    {
        Schema::create( 'admin_activations', function ( Blueprint $table )
        {
            $table->increments( 'id' );
            $table->integer( 'user_id' )->unsigned();
            $table->string( 'code' );
            $table->boolean( 'completed' )->default( 0 );
            $table->timestamp( 'completed_at' )->nullable();
            $table->timestamps();

            $table->engine = 'InnoDB';
        } );

        Schema::create( 'admin_persistences', function ( Blueprint $table )
        {
            $table->increments( 'id' );
            $table->integer( 'user_id' )->unsigned();
            $table->string( 'code' );
            $table->timestamps();

            $table->engine = 'InnoDB';
            $table->unique( 'code' );
        } );

        Schema::create( 'admin_reminders', function ( Blueprint $table )
        {
            $table->increments( 'id' );
            $table->integer( 'user_id' )->unsigned();
            $table->string( 'code' );
            $table->boolean( 'completed' )->default( 0 );
            $table->timestamp( 'completed_at' )->nullable();
            $table->timestamps();

            $table->engine = 'InnoDB';
        } );

        Schema::create( 'admin_roles', function ( Blueprint $table )
        {
            $table->increments( 'id' );
            $table->string( 'slug' );
            $table->string( 'name' );
            $table->text( 'permissions' )->nullable();
            $table->timestamps();

            $table->engine = 'InnoDB';
            $table->unique( 'slug' );
        } );

        Schema::create( 'admin_role_users', function ( Blueprint $table )
        {
            $table->integer( 'user_id' )->unsigned();
            $table->integer( 'role_id' )->unsigned();
            $table->nullableTimestamps();

            $table->engine = 'InnoDB';
            $table->primary( [ 'user_id', 'role_id' ] );
        } );

        Schema::create( 'admin_throttle', function ( Blueprint $table )
        {
            $table->increments( 'id' );
            $table->integer( 'user_id' )->unsigned()->nullable();
            $table->string( 'type' );
            $table->string( 'ip' )->nullable();
            $table->timestamps();

            $table->engine = 'InnoDB';
            $table->index( 'user_id' );
        } );

        Schema::create( 'admin_users', function ( Blueprint $table )
        {
            $table->increments( 'id' );
            $table->string( 'email' );
            $table->string( 'password' );
            $table->text( 'permissions' )->nullable();
            $table->timestamp( 'last_login' )->nullable();
            $table->string( 'first_name' )->nullable();
            $table->string( 'last_name' )->nullable();
            $table->timestamps();

            $table->engine = 'InnoDB';
            $table->unique( 'email' );
        } );
    }
249832
function composeAddRemoveGroupMember({ action="add", roles="members" }) {
  /**
   * Add/Remove user from group
   *
   * @param {String} username
   * @param {String} groupname
   * @param {Function} done - done(err)
   */
   return function(username, groupname, done) {
     return getGroup(groupname, function(getGroupErr, group) {
       if (getGroupErr) {
         return done(getGroupErr);
       }

       if (!group) {
         return done(new Error(`group '${groupname}' not found`));
       }

       return getUser(username, function(getUserErr, user) {
         if (getUserErr) {
           return done(getUserErr);
         }

         if (!user) {
           return done(new Error(`user '${username}' not found`));
         }

         group[roles][action](user.id);
         return group.save(done);
       });
     });
   };
}
126077
def AddGroupMemberships(self):
    """"""
    self.groups = {g.name: self._Members(g) for g in itervalues(self.groups)}
    # Map the groups a user is a member of, irrespective of primary/extra gid.
    for g in itervalues(self.groups):
      for user in g.members:
        membership = self.memberships.setdefault(user, set())
        membership.add(g.gid)
    # Now add the completed membership to the user account.
    for user in itervalues(self.entry):
      user.gids = self.memberships.get(user.username)