Skip to content

Commit

Permalink
Merge pull request #1712 from digitalfabrik/feature/better_organizati…
Browse files Browse the repository at this point in the history
…on_management

Additional organization management
  • Loading branch information
timobrembeck authored Oct 17, 2022
2 parents 146ad3a + 4d54a55 commit f8debc4
Show file tree
Hide file tree
Showing 11 changed files with 351 additions and 49 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- checkout
- restore_cache:
key: pipenv-{{ checksum "Pipfile.lock" }}-v1
key: pipenv-{{ checksum "Pipfile.lock" }}-v2
- run:
name: Install pip dependencies
command: |
Expand All @@ -26,7 +26,7 @@ jobs:
fi
fi
- save_cache:
key: pipenv-{{ checksum "Pipfile.lock" }}-v1
key: pipenv-{{ checksum "Pipfile.lock" }}-v2
paths:
- .venv
- integreat_cms.egg-info
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
- checkout
- restore_cache:
keys:
- npm-{{ checksum "package-lock.json" }}-v1
- npm-{{ checksum "package-lock.json" }}-v2
- run:
name: Install npm dependencies
command: |
Expand All @@ -112,7 +112,7 @@ jobs:
fi
fi
- save_cache:
key: npm-{{ checksum "package-lock.json" }}-v1
key: npm-{{ checksum "package-lock.json" }}-v2
paths:
- node_modules
- run:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ UNRELEASED
* [ [#1710](https://github.com/digitalfabrik/integreat-cms/issues/1710) ] Add spacing to sidebar to improve view on small screens
* [ [#1526](https://github.com/digitalfabrik/integreat-cms/issues/1526)] Fix sending push notifications in one language
* [ [#1630](https://github.com/digitalfabrik/integreat-cms/issues/1630)] Fix not recognized sent status of push notifications
* [ [#1683](https://github.com/digitalfabrik/integreat-cms/issues/1683) ] Improve organization management


2022.10.0
Expand Down
4 changes: 4 additions & 0 deletions integreat_cms/cms/constants/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,19 @@
MANAGEMENT_PERMISSIONS = EDITOR_PERMISSIONS + [
"change_feedback",
"change_imprintpage",
"change_organization",
"change_pushnotification",
"change_user",
"change_chatmessage",
"delete_directory",
"delete_feedback",
"delete_mediafile",
"delete_organization",
"grant_page_permissions",
"send_push_notification",
"view_feedback",
"view_imprintpage",
"view_organization",
"view_pushnotification",
"view_user",
]
Expand Down Expand Up @@ -142,6 +145,7 @@
"delete_imprintpage",
"delete_languagetreenode",
"delete_offertemplate",
"delete_organization",
"delete_page",
"delete_poi",
"delete_poicategory",
Expand Down
51 changes: 51 additions & 0 deletions integreat_cms/cms/forms/organizations/organization_form.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import logging
from django import forms
from django.utils.translation import ugettext_lazy as _

from ...models import Organization
from ..icon_widget import IconWidget
from ..custom_model_form import CustomModelForm
from ...utils.slug_utils import generate_unique_slug_helper


logger = logging.getLogger(__name__)


class OrganizationForm(CustomModelForm):
Expand All @@ -26,3 +34,46 @@ class Meta:
widgets = {
"icon": IconWidget(),
}

def __init__(self, **kwargs):
r"""
Initialize organization form
:param \**kwargs: The supplied keyword arguments
:type \**kwargs: dict
"""
super().__init__(**kwargs)
self.fields["slug"].required = False

def clean_slug(self):
"""
Validate the slug field (see :ref:`overriding-modelform-clean-method`)
:return: A unique slug based on the input value
:rtype: str
"""
return generate_unique_slug_helper(self, "organization")

def clean_name(self):
"""
Validate if form fields name is not already in use for another organization in the same region
(see :ref:`overriding-modelform-clean-method`)
:return: The name which is unique per region
:rtype: str
"""
cleaned_name = self.cleaned_data["name"]
if (
Organization.objects.exclude(id=self.instance.id)
.filter(region=self.instance.region, name=cleaned_name)
.exists()
):
self.add_error(
"name",
forms.ValidationError(
_(
"An organization with the same name already exists in this region. Please choose another name."
),
code="invalid",
),
)
return cleaned_name
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 3.2.11 on 2022-05-18 00:05
from django.db import migrations
from ..constants import roles


# pylint: disable=unused-argument
def update_roles(apps, schema_editor):
"""
Update the role definitions
:param apps: The configuration of installed applications
:type apps: ~django.apps.registry.Apps
:param schema_editor: The database abstraction layer that creates actual SQL code
:type schema_editor: ~django.db.backends.base.schema.BaseDatabaseSchemaEditor
"""
# We can't import the Person model directly as it may be a newer
# version than this migration expects. We use the historical version.
Group = apps.get_model("auth", "Group")
Permission = apps.get_model("auth", "Permission")

# Assign the correct permissions
for role_name in dict(roles.CHOICES):
group = Group.objects.filter(name=role_name).first()
# Clear permissions
group.permissions.clear()
# Set permissions
group.permissions.add(
*Permission.objects.filter(codename__in=roles.PERMISSIONS[role_name])
)


class Migration(migrations.Migration):
"""
Migration file to update the role definitions
"""

dependencies = [
("cms", "0042_alter_pushnotificationtranslation_title"),
]

operations = [
migrations.RunPython(update_roles, migrations.RunPython.noop),
]
17 changes: 17 additions & 0 deletions integreat_cms/cms/models/users/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ def get_repr(self):
"""
return f"<Organization (id: {self.id}, slug: {self.slug}, region: {self.region.slug})>"

@property
def num_pages(self):
"""
:return: the current number of maintained pages of an organization object
:rtype: int
"""
return self.pages.count()

@property
def num_members(self):
"""
:return: the current number of members of an organization object
:rtype: int
"""
return self.members.count()

class Meta:
#: The verbose name of the model
verbose_name = _("organization")
Expand Down
Loading

0 comments on commit f8debc4

Please sign in to comment.