Checks whether a user has permission to perform an action.
        The permission_code parameter should be a permission contained in tPerm.

        If the user does not have permission to perfom an action, a permission
        error is thrown.
509838
def check_perm(user_id, permission_code):
    
    try:
        perm = db.DBSession.query(Perm).filter(Perm.code==permission_code).one()
    except NoResultFound:
        raise PermissionError("Nonexistent permission type: %s"%(permission_code))


    try:
        res = db.DBSession.query(User).join(RoleUser, RoleUser.user_id==User.id).\
            join(Perm, Perm.id==perm.id).\
            join(RolePerm, RolePerm.perm_id==Perm.id).filter(User.id==user_id).one()
    except NoResultFound:
        raise PermissionError("Permission denied. User %s does not have permission %s"%
                        (user_id, permission_code))
910724
def has_object_permission(self, request, view, obj):
        """"""
        # admins can do anything
        if request.user.is_superuser:
            return True

        # `share` permission is required for editing permissions
        if 'permissions' in view.action:
            self.perms_map['POST'] = ['%(app_label)s.share_%(model_name)s']

        if view.action in ['add_data', 'remove_data']:
            self.perms_map['POST'] = ['%(app_label)s.add_%(model_name)s']

        if hasattr(view, 'get_queryset'):
            queryset = view.get_queryset()
        else:
            queryset = getattr(view, 'queryset', None)

        assert queryset is not None, (
            'Cannot apply DjangoObjectPermissions on a view that '
            'does not set `.queryset` or have a `.get_queryset()` method.'
        )

        model_cls = queryset.model
        user = request.user

        perms = self.get_required_object_permissions(request.method, model_cls)

        if not user.has_perms(perms, obj) and not AnonymousUser().has_perms(perms, obj):
            # If the user does not have permissions we need to determine if
            # they have read permissions to see 403, or not, and simply see
            # a 404 response.

            if request.method in permissions.SAFE_METHODS:
                # Read permissions already checked and failed, no need
                # to make another lookup.
                raise Http404

            read_perms = self.get_required_object_permissions('GET', model_cls)
            if not user.has_perms(read_perms, obj):
                raise Http404

            # Has read permissions.
            return False

        return True
546909
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_vote_in_poll(obj, user)
1024033
def has_add_permission(self, request):
        
        opts = self.opts
        return request.user.has_perm(opts.app_label + '.' + opts.get_add_permission())
525879
def has_permission(self, request, view):
        
        if request.method == 'POST':
            user = Profile.objects.only('id', 'username').get(username=view.kwargs['username'])
            return request.user.id == user.id

        return True
365882
def has_import_permission(self, request):
        
        IMPORT_PERMISSION_CODE = getattr(settings, 'IMPORT_EXPORT_IMPORT_PERMISSION_CODE', None)
        if IMPORT_PERMISSION_CODE is None:
            return True

        opts = self.opts
        codename = get_permission_codename(IMPORT_PERMISSION_CODE, opts)
        return request.user.has_perm("%s.%s" % (opts.app_label, codename))
813376
def check_perm(self, request, resource):
        

        perm_name = self.get_perm_name(resource, request.method)
        if not self._has_perm(request.user, perm_name):
            raise errors.Forbidden()
480647
def get_permission(context, method, *args, **kwargs):
    
    request = context.get('request', None)
    perm_handler = request.forum_permission_handler if request else PermissionHandler()

    allowed_methods = inspect.getmembers(perm_handler, predicate=inspect.ismethod)
    allowed_method_names = [a[0] for a in allowed_methods if not a[0].startswith('_')]

    if method not in allowed_method_names:
        raise template.TemplateSyntaxError(
            'Only the following methods are allowed through '
            'this templatetag: {}'.format(allowed_method_names))

    perm_method = getattr(perm_handler, method)
    return perm_method(*args, **kwargs)
1269437
public boolean hasPermissionForUser(String user, String... permission) {
        List<String> params = new ArrayList<>();

        params.add(user);
        Collections.addAll(params, permission);

        return hasPolicy(params);
    }
401817
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_delete_post(obj, user)
699821
def has_object_permission(self, request, view, obj):
        
        user = request.user
        if not user.is_authenticated:
            return False
        elif user.is_staff or user.is_superuser:
            return True
        return user == obj.user
1166927
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_add_post(obj, user)
415653
def check_permission(*permissions, **args_map):
    
    def f1(func, permissions=permissions):
        @wraps(func)
        def f2(*args, **kwargs):
            from uliweb import request, error

            arguments = {}
            for k, v in args_map.items():
                if v in kwargs:
                    arguments[k] = kwargs[v]
            if not has_permission(request.user, *permissions, **arguments):
                error(_("You have no permissions to visit this page."))
            return func(*args, **kwargs)
        return f2
    return f1
875041
public static boolean hasPermission(Permission permission) {
        SecurityManager security = System.getSecurityManager();
        if (security != null) {
            try {
                security.checkPermission(permission);
            } catch (java.security.AccessControlException e) {
                return false;
            }
        }
        return true;
    }
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)
144422
def has_perms(self, perm_list, obj=None):
        
        # If there are no permissions to check, just return true
        if not perm_list:
            return True
        for perm in perm_list:
            if isinstance(perm, six.string_types):
                # check that the permission matches
                if not self.has_perm(perm, obj):
                    return False
            else:
                # check that a permission in the tuple matches
                if not self.has_a_matching_perm(perm, obj):
                    return False
        return True
74178
def check_role_permissions(role, permissions, current_permissions):
    
    role_permissions = []

    # get all the current permissions, we'll remove these as we verify they should still be granted
    for permission in permissions:
        splits = permission.split(".")
        if len(splits) != 2 and len(splits) != 3:
            sys.stderr.write("  invalid permission %s, ignoring\n" % permission)
            continue

        app = splits[0]
        codenames = []

        if len(splits) == 2:
            codenames.append(splits[1])
        else:
            (object, action) = splits[1:]

            # if this is a wildcard, then query our database for all the permissions that exist on this object
            if action == '*':
                for perm in Permission.objects.filter(codename__startswith="%s_" % object, content_type__app_label=app):
                    codenames.append(perm.codename)
            # otherwise, this is an error, continue
            else:
                sys.stderr.write("  invalid permission %s, ignoring\n" % permission)
                continue

        if len(codenames) == 0:
            continue

        for codename in codenames:
            # the full codename for this permission
            full_codename = "%s.%s" % (app, codename)

            # this marks all the permissions which should remain
            role_permissions.append(full_codename)

            try:
                assign_perm(full_codename, role)
            except ObjectDoesNotExist:
                pass
                # sys.stderr.write("  unknown permission %s, ignoring\n" % permission)

    # remove any that are extra
    for permission in current_permissions:
        if isinstance(permission, str):
            key = permission
        else:
            key = "%s.%s" % (permission.content_type.app_label, permission.codename)

        if key not in role_permissions:
            remove_perm(key, role)