Repository: liqd/a4-meinberlin

Issue:
TopicPrio ideas are not editable by other (non admin) inititators
ask @slomo  what happend on friday 


Discussion:
Apparently a rule for checking permissions against items was exexuted on a view that returns an organisation from `get_object`.

```
[2017-10-20 09:42:20 +0200] [ERROR] exception -- Internal Server Error: /dashboard/topics/15-bereich-zentrum-moblierung/update/
Traceback (most recent call last):
  File "/home/django/django/lib/python3.4/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/home/django/django/lib/python3.4/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/django/django/lib/python3.4/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/django/django/lib/python3.4/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/django/django/meinberlin/apps/contrib/views.py", line 105, in dispatch
    .dispatch(request, *args, **kwargs)
  File "/home/django/django/lib/python3.4/site-packages/django/contrib/auth/mixins.py", line 90, in dispatch
    if not self.has_permission():
  File "/home/django/django/lib/python3.4/site-packages/rules/contrib/views.py", line 51, in has_permission
    return self.request.user.has_perms(perms, obj)
  File "/home/django/django/lib/python3.4/site-packages/django/contrib/auth/models.py", line 285, in has_perms
    return all(self.has_perm(perm, obj) for perm in perm_list)
  File "/home/django/django/lib/python3.4/site-packages/django/contrib/auth/models.py", line 285, in <genexpr>
    return all(self.has_perm(perm, obj) for perm in perm_list)
  File "/home/django/django/lib/python3.4/site-packages/django/contrib/auth/models.py", line 277, in has_perm
    return _user_has_perm(self, perm, obj)
  File "/home/django/django/lib/python3.4/site-packages/django/contrib/auth/models.py", line 190, in _user_has_perm
    if backend.has_perm(user, perm, obj):
  File "/home/django/django/lib/python3.4/site-packages/rules/permissions.py", line 28, in has_perm
    return has_perm(perm, user, *args, **kwargs)
  File "/home/django/django/lib/python3.4/site-packages/rules/permissions.py", line 20, in has_perm
    return permissions.test_rule(name, *args, **kwargs)
  File "/home/django/django/lib/python3.4/site-packages/rules/rulesets.py", line 6, in test_rule
    return name in self and self[name].test(*args, **kwargs)
  File "/home/django/django/lib/python3.4/site-packages/rules/predicates.py", line 159, in test
    return bool(self._apply(*args))
  File "/home/django/django/lib/python3.4/site-packages/rules/predicates.py", line 218, in _apply
    result = self.fn(*callargs)
  File "/home/django/django/lib/python3.4/site-packages/adhocracy4/modules/predicates.py", line 59, in is_project_admin
    is_context_moderator(user, item) |
  File "/home/django/django/lib/python3.4/site-packages/rules/predicates.py", line 105, in __call__
    return self.fn(*args, **kwargs)
  File "/home/django/django/lib/python3.4/site-packages/adhocracy4/modules/predicates.py", line 23, in is_context_moderator
    return is_moderator(user, item.project)
AttributeError: 'Organisation' object has no attribute 'project'
```

Resolving patch:
diff --git a/meinberlin/apps/ideas/views.py b/meinberlin/apps/ideas/views.py
--- a/meinberlin/apps/ideas/views.py
+++ b/meinberlin/apps/ideas/views.py
@@ -129,6 +129,7 @@ class IdeaUpdateView(AbstractIdeaUpdateView):
 class AbstractIdeaDeleteView(ProjectContextMixin,
                              rules_mixins.PermissionRequiredMixin,
                              generic.DeleteView):
+    get_context_from_object = True
 
     def get_success_url(self):
         return reverse(
diff --git a/meinberlin/apps/maptopicprio/views.py b/meinberlin/apps/maptopicprio/views.py
--- a/meinberlin/apps/maptopicprio/views.py
+++ b/meinberlin/apps/maptopicprio/views.py
@@ -109,6 +109,9 @@ def get_success_url(self):
             'a4dashboard:maptopic-list',
             kwargs={'module_slug': self.module.slug})
 
+    def get_permission_object(self):
+        return self.module
+
 
 class MapTopicUpdateView(mixins.DashboardBaseMixin,
                          mixins.DashboardComponentMixin,
@@ -127,6 +130,9 @@ def get_success_url(self):
             'a4dashboard:maptopic-list',
             kwargs={'module_slug': self.module.slug})
 
+    def get_permission_object(self):
+        return self.get_object()
+
 
 class MapTopicDeleteView(mixins.DashboardBaseMixin,
                          mixins.DashboardComponentMixin,
@@ -144,3 +150,6 @@ def get_success_url(self):
         return reverse(
             'a4dashboard:maptopic-list',
             kwargs={'module_slug': self.module.slug})
+
+    def get_permission_object(self):
+        return self.get_object()
diff --git a/meinberlin/apps/topicprio/views.py b/meinberlin/apps/topicprio/views.py
--- a/meinberlin/apps/topicprio/views.py
+++ b/meinberlin/apps/topicprio/views.py
@@ -109,6 +109,9 @@ def get_success_url(self):
             'a4dashboard:topic-list',
             kwargs={'module_slug': self.module.slug})
 
+    def get_permission_object(self):
+        return self.module
+
 
 class TopicUpdateView(mixins.DashboardBaseMixin,
                       mixins.DashboardComponentMixin,
@@ -127,6 +130,9 @@ def get_success_url(self):
             'a4dashboard:topic-list',
             kwargs={'module_slug': self.module.slug})
 
+    def get_permission_object(self):
+        return self.get_object()
+
 
 class TopicDeleteView(mixins.DashboardBaseMixin,
                       mixins.DashboardComponentMixin,
@@ -144,3 +150,6 @@ def get_success_url(self):
         return reverse(
             'a4dashboard:topic-list',
             kwargs={'module_slug': self.module.slug})
+
+    def get_permission_object(self):
+        return self.get_object()


Test patch: