Example #1
0
 def get_acl(self, request):
     try:
         acl = cache.get(self.acl_key)
         if acl.version != request.monitor.acl_version:
             raise InvalidCacheBackendError()
     except AttributeError, InvalidCacheBackendError:
         # build acl cache
         acl = build_acl(request, self.get_roles())
         cache.set(self.acl_key, acl, 2592000)
Example #2
0
def get_user_acl(user):
    """
    Get ACL for User
    """
    acl_key = 'acl_%s' % user.acl_key

    acl_cache = threadstore.get(acl_key)
    if not acl_cache:
        acl_cache = cache.get(acl_key)

    if acl_cache and version.is_valid(acl_cache.get('_acl_version')):
        return acl_cache
    else:
        new_acl = build_acl(user.get_roles())
        new_acl['_acl_version'] = version.get_version()

        threadstore.set(acl_key, new_acl)
        cache.set(acl_key, new_acl)

        return new_acl
Example #3
0
def get_user_acl(user):
    """
    Get ACL for User
    """
    acl_key = 'acl_%s' % user.acl_key

    acl_cache = threadstore.get(acl_key)
    if not acl_cache:
        acl_cache = cache.get(acl_key)

    if acl_cache and version.is_valid(acl_cache.get('_acl_version')):
        return acl_cache
    else:
        new_acl = build_acl(user.get_roles())
        new_acl['_acl_version'] = version.get_version()

        threadstore.set(acl_key, new_acl)
        cache.set(acl_key, new_acl)

        return new_acl
Example #4
0
    def notify_mentioned(self, request, thread_type, users):
        from misago.acl.builder import acl as build_acl
        from misago.acl.exceptions import ACLError403, ACLError404

        mentioned = self.mentions.all()
        for slug, user in users.items():
            if user.pk != request.user.pk and user not in mentioned:
                self.mentions.add(user)
                try:
                    user_acl = build_acl(request, user)
                    user_acl.forums.allow_forum_view(self.forum)
                    user_acl.threads.allow_thread_view(user, self.thread)
                    user_acl.threads.allow_post_view(user, self.thread, self)
                    if not user.is_ignoring(request.user):
                        alert = user.alert(ugettext_lazy("%(username)s has mentioned you in his reply in thread %(thread)s").message)
                        alert.profile('username', request.user)
                        alert.post('thread', thread_type, self.thread, self)
                        alert.save_all()
                except (ACLError403, ACLError404):
                    pass