Alter a database user and/or their permissions.

        :param permissions: A ``(readFrom, writeTo)`` tuple
        :raise TypeError: if permissions cannot be read.
        :raise ValueError: if neither password nor permissions provided.
547397
def alter_database_user(self, username, password=None, permissions=None):
        
        url = "db/{0}/users/{1}".format(self._database, username)

        if not password and not permissions:
            raise ValueError("Nothing to alter for user {0}.".format(username))

        data = {}

        if password:
            data['password'] = password

        if permissions:
            try:
                data['readFrom'], data['writeTo'] = permissions
            except (ValueError, TypeError):
                raise TypeError(
                    "'permissions' must be (readFrom, writeTo) tuple"
                )

        self.request(
            url=url,
            method='POST',
            data=data,
            expected_response_code=200
        )

        if username == self._username:
            self._password = password

        return True
951018
def set_permission(self, permission, value, parent=False, admin=False):
        
        try:
            if not getattr(self, 'parent_{}'.format(permission)) and not parent and not admin:
                return False
            level = 'parent' if parent else 'self'
            setattr(self, '{}_{}'.format(level, permission), value)

            # Set student permission to false if parent sets permission to false.
            if parent and not value:
                setattr(self, 'self_{}'.format(permission), False)

            self.save()
            return True
        except Exception as e:
            logger.error("Error occurred setting permission {} to {}: {}".format(permission, value, e))
            return False
1250289
def get_permissions(self, user, obj=_nothing):
        
        rule = self._get_rule(obj)

        all_permissions = (
            attr[len('can_'):] for attr in dir(rule)
            if attr.startswith('can_')
        )

        return set(
            permission for permission in all_permissions
            if self.allows(user, permission, obj)
        )
1153054
private void setRWPermissions(File f) {
    if (!f.setReadable(true, false) || !f.setWritable(true, false)) {
      LOG.info("Could not set permissions for file : "
          + f + " probably because user : " + System.getProperty("user.name")
          + " is not the owner");
    }
  }
593676
def write_user(user):
    

    udata = {}

    for f in USER_FIELDS:
        udata[f] = getattr(user, f)

    for p in PERMISSIONS:
        udata[p] = '1' if getattr(user, p) else '0'
    db.hmset('user:{0}'.format(user.uid), udata)
635104
def set_model_permissions(context, token):
    
    model = context[token.split_contents()[1]]
    opts = model._meta
    perm_name = opts.app_label + ".%s_" + opts.object_name.lower()
    request = context["request"]
    setattr(model, "perms", {})
    for perm_type in ("add", "change", "delete"):
        model.perms[perm_type] = request.user.has_perm(perm_name % perm_type)
    return ""
1012712
public void updatePermissions() {
    final String[] accessViewerList =
        this.accessViewer.trim().split(ACCESS_LIST_SPLIT_REGEX);
    final String[] accessExecutorList =
        this.accessExecutor.trim().split(ACCESS_LIST_SPLIT_REGEX);
    final String[] accessOwnerList =
        this.accessOwner.trim().split(ACCESS_LIST_SPLIT_REGEX);
    // Prepare permission types
    final Permission admin = new Permission();
    admin.addPermission(Type.READ);
    admin.addPermission(Type.EXECUTE);
    admin.addPermission(Type.ADMIN);
    final Permission executor = new Permission();
    executor.addPermission(Type.READ);
    executor.addPermission(Type.EXECUTE);
    final Permission viewer = new Permission();
    viewer.addPermission(Type.READ);
    // Sets the permissions
    this.project.clearUserPermission();
    for (String user : accessViewerList) {
      user = user.trim();
      if (!user.isEmpty()) {
        this.project.setUserPermission(user, viewer);
      }
    }
    for (String user : accessExecutorList) {
      user = user.trim();
      if (!user.isEmpty()) {
        this.project.setUserPermission(user, executor);
      }
    }
    for (String user : accessOwnerList) {
      user = user.trim();
      if (!user.isEmpty()) {
        this.project.setUserPermission(user, admin);
      }
    }
    this.project.setUserPermission(this.reportalUser, admin);
  }
1220338
public void setPermissions(String newPermissions) {
		int cp = 0;

		if (permissions != null) {
			cp = cp
					| (((permissions.longValue() & S_IFMT) == S_IFMT) ? S_IFMT
							: 0);
			cp = cp
					| (((permissions.longValue() & S_IFSOCK) == S_IFSOCK) ? S_IFSOCK
							: 0);
			cp = cp
					| (((permissions.longValue() & S_IFLNK) == S_IFLNK) ? S_IFLNK
							: 0);
			cp = cp
					| (((permissions.longValue() & S_IFREG) == S_IFREG) ? S_IFREG
							: 0);
			cp = cp
					| (((permissions.longValue() & S_IFBLK) == S_IFBLK) ? S_IFBLK
							: 0);
			cp = cp
					| (((permissions.longValue() & S_IFDIR) == S_IFDIR) ? S_IFDIR
							: 0);
			cp = cp
					| (((permissions.longValue() & S_IFCHR) == S_IFCHR) ? S_IFCHR
							: 0);
			cp = cp
					| (((permissions.longValue() & S_IFIFO) == S_IFIFO) ? S_IFIFO
							: 0);
			cp = cp
					| (((permissions.longValue() & S_ISUID) == S_ISUID) ? S_ISUID
							: 0);
			cp = cp
					| (((permissions.longValue() & S_ISGID) == S_ISGID) ? S_ISGID
							: 0);
		}

		int len = newPermissions.length();

		if (len >= 1) {
			cp = cp
					| ((newPermissions.charAt(0) == 'r') ? SftpFileAttributes.S_IRUSR
							: 0);
		}

		if (len >= 2) {
			cp = cp
					| ((newPermissions.charAt(1) == 'w') ? SftpFileAttributes.S_IWUSR
							: 0);
		}

		if (len >= 3) {
			cp = cp
					| ((newPermissions.charAt(2) == 'x') ? SftpFileAttributes.S_IXUSR
							: 0);
		}

		if (len >= 4) {
			cp = cp
					| ((newPermissions.charAt(3) == 'r') ? SftpFileAttributes.S_IRGRP
							: 0);
		}

		if (len >= 5) {
			cp = cp
					| ((newPermissions.charAt(4) == 'w') ? SftpFileAttributes.S_IWGRP
							: 0);
		}

		if (len >= 6) {
			cp = cp
					| ((newPermissions.charAt(5) == 'x') ? SftpFileAttributes.S_IXGRP
							: 0);
		}

		if (len >= 7) {
			cp = cp
					| ((newPermissions.charAt(6) == 'r') ? SftpFileAttributes.S_IROTH
							: 0);
		}

		if (len >= 8) {
			cp = cp
					| ((newPermissions.charAt(7) == 'w') ? SftpFileAttributes.S_IWOTH
							: 0);
		}

		if (len >= 9) {
			cp = cp
					| ((newPermissions.charAt(8) == 'x') ? SftpFileAttributes.S_IXOTH
							: 0);
		}

		setPermissions(new UnsignedInteger32(cp));
	}
1301921
public void changePermissions(String filename, String permissions)
			throws SftpStatusException, SshException {

		SftpFileAttributes attrs = new SftpFileAttributes(this,
				SftpFileAttributes.SSH_FILEXFER_TYPE_UNKNOWN);
		attrs.setPermissions(permissions);
		setAttributes(filename, attrs);

	}
788792
def grant_user_access(self, instance, user, db_names, strict=True):
        
        return instance.grant_user_access(user, db_names, strict=strict)
1239598
def permission_table(user_permissions, all_permissions):
    """"""

    table = formatting.Table(['Description', 'KeyName', 'Assigned'])
    table.align['KeyName'] = 'l'
    table.align['Description'] = 'l'
    table.align['Assigned'] = 'l'
    for perm in all_permissions:
        assigned = user_permissions.get(perm['keyName'], False)
        table.add_row([perm['name'], perm['keyName'], assigned])
    return table
498962
def update_permissions_for_group(apps, schema_editor):
    '''
    
    '''
    db_alias = schema_editor.connection.alias
    try:
        # Django 1.9
        emit_post_migrate_signal(2, False, db_alias)
    except TypeError:
        # Django < 1.9
        try:
            # Django 1.8
            emit_post_migrate_signal(2, False, 'default', db_alias)
        except TypeError:  # Django < 1.8
            emit_post_migrate_signal([], 2, False, 'default', db_alias)

    Group = apps.get_model('auth.Group')
    Permission = apps.get_model('auth.Permission')
    GroupPagePermission = apps.get_model('wagtailcore.GroupPagePermission')
    SectionIndexPage = apps.get_model('core.SectionIndexPage')
    MainPage = apps.get_model('core.Main')

    moderator_group = Group.objects.filter(name='Moderators').first()
    editor_group = Group.objects.filter(name='Editors').first()

    if moderator_group:
        sections = SectionIndexPage.objects.first()
        GroupPagePermission.objects.get_or_create(
            group_id=moderator_group.id,
            page_id=sections.id,
            permission_type='bulk_delete'
        )

        main = MainPage.objects.first()
        GroupPagePermission.objects.get_or_create(
            group_id=moderator_group.id,
            page_id=main.id,
            permission_type='edit'
        )

    if editor_group:
        main = MainPage.objects.first()
        GroupPagePermission.objects.get_or_create(
            group_id=editor_group.id,
            page_id=main.id,
            permission_type='edit'
        )
468449
public void setUserPermission(String userName, List<Permission> permissions){
        getServiceDirectoryClient().setACL(new ACL(AuthScheme.DIRECTORY, userName, PermissionUtil.permissionList2Id(permissions)));
    }
1070348
public void setPermissions(UnsignedInteger32 permissions) {
		this.permissions = permissions;

		// Set the flag
		if (permissions != null) {
			flags |= SSH_FILEXFER_ATTR_PERMISSIONS;
		} else {
			flags ^= SSH_FILEXFER_ATTR_PERMISSIONS;
		}
	}
134301
def group_perms_for_user(cls, instance, user, db_session=None):
        
        db_session = get_db_session(db_session, instance)
        perms = resource_permissions_for_users(
            cls.models_proxy,
            ANY_PERMISSION,
            resource_ids=[instance.resource_id],
            user_ids=[user.id],
            db_session=db_session,
        )
        perms = [p for p in perms if p.type == "group"]
        # include all perms if user is the owner of this resource
        groups_dict = dict([(g.id, g) for g in user.groups])
        if instance.owner_group_id in groups_dict:
            perms.append(
                PermissionTuple(
                    user,
                    ALL_PERMISSIONS,
                    "group",
                    groups_dict.get(instance.owner_group_id),
                    instance,
                    True,
                    True,
                )
            )
        return perms
74452
def ensure_permissions(mode_flags=stat.S_IWUSR):
    

    def decorator(f):
        def modify(filename, *args, **kwargs):
            m = chmod_perms(filename) if exists(filename) else mode_flags
            if not m & mode_flags:
                os.chmod(filename, m | mode_flags)
            try:
                return f(filename, *args, **kwargs)
            finally:
                # restore original permissions
                if not m & mode_flags:
                    os.chmod(filename, m)
        return modify

    return decorator
283916
def permissions(self, **kwargs):
        
        self._validate_loaded()
        return TailoredAudiencePermission.all(self.account, self.id, **kwargs)