From 6e10d56479de8312ffa8623676055a882f5e73ee Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Thu, 7 Jul 2016 19:42:23 -0400 Subject: [PATCH 1/6] Only add 'auth.local' to MODULES when AUTH_LOCAL_ENABLED is True --- realms/config/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realms/config/__init__.py b/realms/config/__init__.py index 891f0ea..8a3f0b0 100644 --- a/realms/config/__init__.py +++ b/realms/config/__init__.py @@ -145,7 +145,7 @@ class Config(object): def __init__(self): for k, v in self.read().iteritems(): setattr(self, k, v) - if hasattr(self, 'AUTH_LOCAL_ENABLE'): + if getattr(self, 'AUTH_LOCAL_ENABLE', True): self.MODULES.append('auth.local') if hasattr(self, 'OAUTH'): self.MODULES.append('auth.oauth') From 3c3d39c771c99241a53f6d3849ec60b0fd1aba0a Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Thu, 7 Jul 2016 20:05:11 -0400 Subject: [PATCH 2/6] Fix clearing cache on page edits with new WikiPage refactor --- realms/modules/wiki/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realms/modules/wiki/models.py b/realms/modules/wiki/models.py index 3c3a160..2d12d18 100644 --- a/realms/modules/wiki/models.py +++ b/realms/modules/wiki/models.py @@ -176,7 +176,7 @@ class WikiPage(object): return username, email def _clear_cache(self): - cache.delete_many(self._cache_key(p) for p in ['data', 'info']) + cache.delete_many(*(self._cache_key(p) for p in ['data', 'info'])) def delete(self, username=None, email=None, message=None): """Delete page. From c0a4e6b480e66b95023635fea312f7a968cf0d98 Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Fri, 8 Jul 2016 02:10:26 -0400 Subject: [PATCH 3/6] Pass self to HookMixin hooks --- realms/lib/hook.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/realms/lib/hook.py b/realms/lib/hook.py index bf6a00e..61d2885 100644 --- a/realms/lib/hook.py +++ b/realms/lib/hook.py @@ -7,7 +7,7 @@ def hook_func(name, fn): @wraps(fn) def wrapper(self, *args, **kwargs): for hook, a, kw in self.__class__._pre_hooks.get(name) or []: - hook(*args, **kwargs) + hook(self, *args, **kwargs) rv = fn(self, *args, **kwargs) @@ -15,7 +15,7 @@ def hook_func(name, fn): kwargs.update(dict(rv=rv)) for hook, a, kw in self.__class__._post_hooks.get(name) or []: - hook(*args, **kwargs) + hook(self, *args, **kwargs) return rv return wrapper From ed0ac58e6fa26eb56a075bff3af60ccd35ef3448 Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Fri, 8 Jul 2016 02:11:57 -0400 Subject: [PATCH 4/6] Update search module hooks to use new WikiPage methods --- realms/modules/search/hooks.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/realms/modules/search/hooks.py b/realms/modules/search/hooks.py index 25a7d12..abf7346 100644 --- a/realms/modules/search/hooks.py +++ b/realms/modules/search/hooks.py @@ -1,35 +1,40 @@ -from realms.modules.wiki.models import Wiki +from realms.modules.wiki.models import WikiPage from realms import search -@Wiki.after('write_page') -def wiki_write_page(name, content, message=None, username=None, email=None, **kwargs): +@WikiPage.after('write') +def wiki_write_page(page, content, message=None, username=None, email=None, **kwargs): if not hasattr(search, 'index_wiki'): # using simple search or none return - body = dict(name=name, + body = dict(name=page.name, content=content, message=message, email=email, username=username) - return search.index_wiki(name, body) + return search.index_wiki(page.name, body) -@Wiki.after('rename_page') -def wiki_rename_page(old_name, *args, **kwargs): +@WikiPage.before('rename') +def wiki_rename_page_del(page, *args, **kwargs): if not hasattr(search, 'index_wiki'): return - return search.delete_wiki(old_name) + return search.delete_wiki(page.name) -@Wiki.after('delete_page') -def wiki_delete_page(name, *args, **kwargs): +@WikiPage.after('rename') +def wiki_rename_page_add(page, new_name, *args, **kwargs): + wiki_write_page(page, page.data, *args, **kwargs) + + +@WikiPage.after('delete') +def wiki_delete_page(page, *args, **kwargs): if not hasattr(search, 'index_wiki'): return - return search.delete_wiki(name) + return search.delete_wiki(page.name) From 1bc15594f669f130a9f6569c3091228b241b6462 Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Fri, 8 Jul 2016 13:53:09 -0400 Subject: [PATCH 5/6] Allow WikiPage methods to be hooked --- realms/modules/wiki/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realms/modules/wiki/models.py b/realms/modules/wiki/models.py index 2d12d18..2bb8e1d 100644 --- a/realms/modules/wiki/models.py +++ b/realms/modules/wiki/models.py @@ -69,7 +69,7 @@ class Wiki(HookMixin): return rv -class WikiPage(object): +class WikiPage(HookMixin): def __init__(self, name, wiki, sha='HEAD'): self.name = name self.filename = cname_to_filename(name) From 3d14412604d5fd512fc38d20e30e0d21e694954d Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Fri, 8 Jul 2016 18:56:40 -0400 Subject: [PATCH 6/6] Ensure git repo remains valid with unicode committer names. fix #152 --- realms/modules/wiki/models.py | 45 +++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/realms/modules/wiki/models.py b/realms/modules/wiki/models.py index 2bb8e1d..318b7ae 100644 --- a/realms/modules/wiki/models.py +++ b/realms/modules/wiki/models.py @@ -40,6 +40,27 @@ class Wiki(HookMixin): def __repr__(self): return "Wiki: %s" % self.path + def commit(self, name, email, message, files): + """Commit to the underlying git repo. + + :param name: Committer name + :param email: Committer email + :param message: Commit message + :param files: list of file names that should be committed + :return: + """ + # Dulwich and gittle seem to want us to encode ourselves at the moment. see #152 + if isinstance(name, unicode): + name = name.encode('utf-8') + if isinstance(email, unicode): + email = email.encode('utf-8') + if isinstance(message, unicode): + message = message.encode('utf-8') + return self.gittle.commit(name=name, + email=email, + message=message, + files=files) + def get_page(self, name, sha='HEAD'): """Get page data, partials, commit info. @@ -193,10 +214,10 @@ class WikiPage(HookMixin): # gittle.rm won't actually remove the file, have to do it ourselves os.remove(os.path.join(self.wiki.path, self.filename)) self.wiki.gittle.rm(self.filename) - commit = self.wiki.gittle.commit(name=username, - email=email, - message=message, - files=[self.filename]) + commit = self.wiki.commit(name=username, + email=email, + message=message, + files=[self.filename]) self._clear_cache() return commit @@ -230,10 +251,10 @@ class WikiPage(HookMixin): self.wiki.gittle.add(new_filename) self.wiki.gittle.rm(old_filename) - commit = self.wiki.gittle.commit(name=username, - email=email, - message=message, - files=[old_filename, new_filename]) + commit = self.wiki.commit(name=username, + email=email, + message=message, + files=[old_filename, new_filename]) self._clear_cache() self.name = new_name @@ -270,10 +291,10 @@ class WikiPage(HookMixin): username, email = self._get_user(username, email) - ret = self.wiki.gittle.commit(name=username, - email=email, - message=message, - files=[self.filename]) + ret = self.wiki.commit(name=username, + email=email, + message=message, + files=[self.filename]) self._clear_cache() return ret