-
-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
300 changed files
with
5,802 additions
and
5,797 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .api import get_user_acl, add_acl, serialize_acl | ||
|
||
default_app_config = 'misago.acl.apps.MisagoACLsConfig' | ||
|
||
ACL_CACHE = "acl" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.core.cache import cache | ||
|
||
from misago.cache.versions import invalidate_cache | ||
|
||
from . import ACL_CACHE | ||
|
||
|
||
def get_acl_cache(user, cache_versions): | ||
key = get_cache_key(user, cache_versions) | ||
return cache.get(key) | ||
|
||
|
||
def set_acl_cache(user, cache_versions, user_acl): | ||
key = get_cache_key(user, cache_versions) | ||
cache.set(key, user_acl) | ||
|
||
|
||
def get_cache_key(user, cache_versions): | ||
return 'acl_%s_%s' % (user.acl_key, cache_versions[ACL_CACHE]) | ||
|
||
|
||
def clear_acl_cache(): | ||
invalidate_cache(ACL_CACHE) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def user_acl(request): | ||
return {"user_acl": request.user_acl} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.utils.functional import SimpleLazyObject | ||
|
||
from . import useracl | ||
|
||
|
||
def user_acl_middleware(get_response): | ||
"""Sets request.user_acl attribute with dict containing current user acl.""" | ||
def middleware(request): | ||
request.user_acl = useracl.get_user_acl(request.user, request.cache_versions) | ||
return get_response(request) | ||
|
||
return middleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
from django.db import migrations | ||
|
||
from misago.acl.constants import ACL_CACHEBUSTER | ||
from misago.core.migrationutils import cachebuster_register_cache | ||
|
||
|
||
def register_acl_version_tracker(apps, schema_editor): | ||
cachebuster_register_cache(apps, ACL_CACHEBUSTER) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
"""Superseded by 0004""" | ||
|
||
dependencies = [ | ||
('misago_acl', '0001_initial'), | ||
('misago_core', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(register_acl_version_tracker), | ||
] | ||
operations = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.db import migrations | ||
|
||
from misago.acl import ACL_CACHE | ||
from misago.cache.operations import StartCacheVersioning | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('misago_acl', '0003_default_roles'), | ||
('misago_cache', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
StartCacheVersioning(ACL_CACHE) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from .providers import providers | ||
|
||
|
||
def add_acl_to_obj(user_acl, obj): | ||
"""add valid ACL to obj (iterable of objects or single object)""" | ||
if hasattr(obj, '__iter__'): | ||
for item in obj: | ||
_add_acl_to_obj(user_acl, item) | ||
else: | ||
_add_acl_to_obj(user_acl, obj) | ||
|
||
|
||
def _add_acl_to_obj(user_acl, obj): | ||
"""add valid ACL to single obj, helper for add_acl function""" | ||
obj.acl = {} | ||
|
||
for annotator in providers.get_obj_type_annotators(obj): | ||
annotator(user_acl, obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from contextlib import ContextDecorator, ExitStack, contextmanager | ||
from functools import wraps | ||
from unittest.mock import patch | ||
|
||
from .useracl import get_user_acl | ||
|
||
__all__ = ["patch_user_acl"] | ||
|
||
|
||
class patch_user_acl(ContextDecorator, ExitStack): | ||
"""Testing utility that patches get_user_acl results | ||
Can be used as decorator or context manager. | ||
Patch should be a dict or callable. | ||
""" | ||
|
||
_acl_patches = [] | ||
|
||
def __init__(self, acl_patch): | ||
super().__init__() | ||
self.acl_patch = acl_patch | ||
|
||
def patched_get_user_acl(self, user, cache_versions): | ||
user_acl = get_user_acl(user, cache_versions) | ||
self.apply_acl_patches(user, user_acl) | ||
return user_acl | ||
|
||
def apply_acl_patches(self, user, user_acl): | ||
for acl_patch in self._acl_patches: | ||
self.apply_acl_patch(user, user_acl, acl_patch) | ||
|
||
def apply_acl_patch(self, user, user_acl, acl_patch): | ||
if callable(acl_patch): | ||
acl_patch(user, user_acl) | ||
else: | ||
user_acl.update(acl_patch) | ||
|
||
def __enter__(self): | ||
super().__enter__() | ||
self.enter_context(self.enable_acl_patch()) | ||
self.enter_context(self.patch_user_acl()) | ||
|
||
@contextmanager | ||
def enable_acl_patch(self): | ||
try: | ||
self._acl_patches.append(self.acl_patch) | ||
yield | ||
finally: | ||
self._acl_patches.pop(-1) | ||
|
||
def patch_user_acl(self): | ||
return patch( | ||
"misago.acl.useracl.get_user_acl", | ||
side_effect=self.patched_get_user_acl, | ||
) |
Oops, something went wrong.