Adds a permission to the current environment.

@param perm the permission to add.

@return the old attribute value
771287
public static void addPermission(Permission perm, ClassLoader loader)
  {
    for (; loader != null; loader = loader.getParent()) {
      if (loader instanceof EnvironmentClassLoader) {
        EnvironmentClassLoader envLoader = (EnvironmentClassLoader) loader;

        envLoader.addPermission(perm);
      }
    }
  }
1246836
@Override
    public void add(IPermission perm) throws AuthorizationException {

        Connection conn = null;
        int rc = 0;

        try {
            conn = RDBMServices.getConnection();
            String sQuery = getInsertPermissionSql();
            PreparedStatement ps = conn.prepareStatement(sQuery);
            try {
                primAdd(perm, ps);
                if (log.isDebugEnabled()) log.debug("RDBMPermissionImpl.add(): " + ps);
                rc = ps.executeUpdate();
                if (rc != 1) {
                    throw new AuthorizationException("Problem adding Permission " + perm);
                }
            } finally {
                ps.close();
            }
        } catch (Exception ex) {
            log.error("Exception adding permission [" + perm + "]", ex);
            throw new AuthorizationException("Problem adding Permission " + perm);
        } finally {
            RDBMServices.releaseConnection(conn);
        }
    }
204869
def has_update_permission(self, request, obj):
        
        perm_string = '%s.change_%s' % (self.model._meta.app_label,
            self.model._meta.object_name.lower()
        )
        return request.user.has_perm(perm_string)
246678
def has_perm(self, user, perm, obj=None):
        """"""
        if not user.is_active:
            return False
        return perm in self.get_all_permissions(user, obj)
1187022
function addPermission(rbac, action, resource, cb) {
  rbac.getPermission(action, resource, (err, permission) => {
    if (err) {
      return cb(err);
    }

    if (!permission) {
      return cb(new Error('Permission not exists'));
    }

    if (indexOf(this.permissions, permission.name) !== -1) {
      return cb(new Error('Permission is already assigned'));
    }

    this.permissions.push(permission.name);
    return this.save((err2, user) => {
      if (err2) {
        return cb(err2);
      }

      if (!user) {
        return cb(new Error('User is undefined'));
      }

      return cb(null, true);
    });
  });

  return this;
}
992806
def has_add_permission(self, request):
        
        perm_string = '%s.add_%s' % (self.model._meta.app_label,
            self.model._meta.object_name.lower()
        )
        return request.user.has_perm(perm_string)
829346
def has_perm(self, perm):
        
        if '.' in perm:
            app_label, codename = perm.split('.')
            permissions = self.permissions.filter(
                content_type__app_label = app_label, 
                codename = codename)
            groups = self.groups.filter(
                permissions__content_type__app_label = app_label,
                permissions__codename = codename )
        else:
            permissions = self.permissions.filter(codename = perm)
            groups = self.groups.filter(permissions__codename = perm)
        return permissions.exists() or groups.exists()
117166
private Delta createDelta(PermissionUpdateRequest request) {
        MapDeltaBuilder builder = Deltas.mapBuilder();

        for (String permissionString : request.getPermitted()) {
            builder.put("perm_" + validated(permissionString), 1);
        }
        for (String permissionString : request.getRevoked()) {
            builder.remove("perm_" + validated(permissionString));
        }
        if (request.isRevokeRest()) {
            builder.removeRest();
        }
        return builder.build();
    }
1157226
@Override
	public boolean addPermission(Permission permission)
	{
		if(permissions.contains(permission))
			return false;
		
		return this.permissions.add(permission);
	}
568763
def add_permission_role(self, role, perm_view):
        
        if perm_view not in role.permissions:
            try:
                role.permissions.append(perm_view)
                role.save()
                log.info(
                    c.LOGMSG_INF_SEC_ADD_PERMROLE.format(str(perm_view), role.name)
                )
            except Exception as e:
                log.error(c.LOGMSG_ERR_SEC_ADD_PERMROLE.format(str(e)))
1150852
def assign_perm(perm, user_or_group, forum=None, has_perm=True):
    
    user, group = get_identity(user_or_group)
    perm = ForumPermission.objects.get(codename=perm)
    if user:
        return UserForumPermission.objects.create(
            forum=forum,
            permission=perm,
            user=user if not user.is_anonymous else None,
            anonymous_user=user.is_anonymous,
            has_perm=has_perm,
        )
    if group:
        return GroupForumPermission.objects.create(
            forum=forum, permission=perm, group=group, has_perm=has_perm,
        )
1276113
public function perms()
    {
        return $this->belongsToMany(Config::get('entrust.permission'), Config::get('entrust.permission_role_table'), Config::get('entrust.role_foreign_key'), Config::get('entrust.permission_foreign_key'));
    }
217614
public function grant($perm, DataObject $to, $grant = 'GRANT')
    {
        return singleton('PermissionService')->grant($this->owner, $perm, $to, $grant);
    }
809026
def requested_perm(self, perm, obj, check_groups=True):
        
        return self.has_perm(perm, obj, check_groups, False)
380421
@Post("/metadata/{projectName}/repos/{repoName}/perm/users")
    public CompletableFuture<Revision> addSpecificUserPermission(
            @Param("projectName") String projectName,
            @Param("repoName") String repoName,
            IdentifierWithPermissions memberWithPermissions,
            Author author) {
        final User member = new User(loginNameNormalizer.apply(memberWithPermissions.id()));
        return mds.addPerUserPermission(author, projectName, repoName,
                                        member, memberWithPermissions.permissions());
    }
1040459
def get_permission_required(cls):
        
        if cls.permission_required is None:
            raise ImproperlyConfigured(
                "{0} is missing the permission_required attribute. "
                "Define {0}.permission_required, or override "
                "{0}.get_permission_required().".format(cls.__name__)
            )
        if isinstance(cls.permission_required, six.string_types):
            if cls.permission_required != "":
                perms = (cls.permission_required,)
            else:
                perms = ()
        else:
            perms = cls.permission_required

        return perms
633069
def _check_perms_changes(name, newperms, runas=None, existing=None):
    '''
    
    '''
    if not newperms:
        return False

    if existing is None:
        try:
            existing = __salt__['rabbitmq.list_user_permissions'](name, runas=runas)
        except CommandExecutionError as err:
            log.error('Error: %s', err)
            return False

    perm_need_change = False
    for vhost_perms in newperms:
        for vhost, perms in six.iteritems(vhost_perms):
            if vhost in existing:
                existing_vhost = existing[vhost]
                if perms != existing_vhost:
                    # This checks for setting permissions to nothing in the state,
                    # when previous state runs have already set permissions to
                    # nothing. We don't want to report a change in this case.
                    if existing_vhost == '' and perms == ['', '', '']:
                        continue
                    perm_need_change = True
            else:
                perm_need_change = True

    return perm_need_change