Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add orga setting 'require_duplicate_from' #2524

Merged
merged 9 commits into from
Jul 30, 2024
1 change: 1 addition & 0 deletions docs/actions/meeting.create.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ It translates created objects (eg. groups, workflow, states, ...) to the given l

## Permissions
The user must have CML `can_manage`.
If the organization setting: `require_duplicate_from` is set, OML rights are required.
1 change: 1 addition & 0 deletions docs/actions/organization.update.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
users_email_subject: string;
users_email_body: text;
genders: string[];
require_duplicate_from: boolean;

// Group B
enable_electronic_voting: boolean;
Expand Down
1 change: 1 addition & 0 deletions global/data/example-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"users_email_body": "Dear {name},\n\nthis is your personal OpenSlides login:\n\n{url}\nUsername: {username}\nPassword: {password}\n\n\nThis email was generated automatically.",
"url": "https://example.com",
"user_ids": [1, 2, 3],
"require_duplicate_from": false,
"saml_enabled": false,
"saml_login_button_text": "SAML Login",
"saml_attr_mapping": {
Expand Down
1 change: 1 addition & 0 deletions global/data/initial-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"template_meeting_ids": [],
"mediafile_ids": [],
"user_ids": [1],
"require_duplicate_from": false,
"saml_enabled": false,
"saml_login_button_text": "SAML Login",
"saml_attr_mapping": {
Expand Down
2 changes: 1 addition & 1 deletion global/meta
Submodule meta updated 1 files
+3 −0 models.yml
17 changes: 16 additions & 1 deletion openslides_backend/action/actions/meeting/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from ....i18n.translator import Translator
from ....i18n.translator import translate as _
from ....permissions.management_levels import OrganizationManagementLevel
from ....permissions.permission_helper import has_organization_management_level
from ....permissions.permissions import Permissions
from ....shared.exceptions import ActionException
from ....shared.patterns import fqid_from_collection_and_id, id_from_fqid
Expand Down Expand Up @@ -79,14 +81,27 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:

organization = self.datastore.get(
ONE_ORGANIZATION_FQID,
["limit_of_meetings", "active_meeting_ids"],
[
"limit_of_meetings",
"active_meeting_ids",
"require_duplicate_from",
],
)
if (
limit_of_meetings := organization.get("limit_of_meetings", 0)
) and limit_of_meetings == len(organization.get("active_meeting_ids", [])):
raise ActionException(
f"You cannot create a new meeting, because you reached your limit of {limit_of_meetings} active meetings."
)

if organization.get(
"require_duplicate_from"
) and not has_organization_management_level(
self.datastore, self.user_id, OrganizationManagementLevel.CAN_MANAGE_USERS
):
raise ActionException(
"You cannot create a new meeting, because you need to use a template."
)
self.check_start_and_end_time(instance)

instance["is_active_in_organization_id"] = ONE_ORGANIZATION_ID
Expand Down
1 change: 1 addition & 0 deletions openslides_backend/action/actions/organization/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class OrganizationUpdate(
"users_email_subject",
"users_email_body",
"genders",
"require_duplicate_from",
)

group_B_fields = (
Expand Down
1 change: 1 addition & 0 deletions openslides_backend/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Organization(Model):
default_language = fields.CharField(
required=True, constraints={"enum": ["en", "de", "it", "es", "ru", "cs", "fr"]}
)
require_duplicate_from = fields.BooleanField()
saml_enabled = fields.BooleanField()
saml_login_button_text = fields.CharField(default="SAML login")
saml_attr_mapping = fields.JSONField()
Expand Down
23 changes: 22 additions & 1 deletion tests/system/action/meeting/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@

class MeetingCreateActionTest(BaseActionTestCase):
def basic_test(
self, datapart: dict[str, Any], set_400_str: str = ""
self,
datapart: dict[str, Any],
set_400_str: str = "",
orga_settings: dict[str, Any] | None = None,
) -> dict[str, Any]:
if orga_settings is None:
orga_settings = {}
self.set_models(
{
ONE_ORGANIZATION_FQID: {
"limit_of_meetings": 0,
"active_meeting_ids": [],
**orga_settings,
},
"committee/1": {
"name": "test_committee",
Expand Down Expand Up @@ -512,3 +518,18 @@ def test_create_external_id_empty_special_case(self) -> None:
"external_id": external_id,
},
)

def test_enable_duplicate_mandatory(self) -> None:
self.set_models(
{
"user/1": {
"organization_management_level": None,
"committee_management_ids": [1],
}
}
)
self.basic_test(
{},
set_400_str="You cannot create a new meeting, because you need to use a template.",
orga_settings={"require_duplicate_from": True},
)
2 changes: 2 additions & 0 deletions tests/system/action/organization/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def test_update_some_more_fields(self) -> None:
"users_email_replyto": " [email protected] ",
"users_email_subject": "email subject",
"users_email_body": "Dear {name},\n\nthis is your personal OpenSlides login:\n\n{url}\nUsername: {username}\nPassword: {password}\n\n\nThis email was generated automatically.",
"require_duplicate_from": True,
"saml_enabled": True,
"saml_login_button_text": "Text for SAML login button",
"saml_attr_mapping": self.saml_attr_mapping,
Expand Down Expand Up @@ -165,6 +166,7 @@ def test_update_some_more_fields(self) -> None:
"users_email_replyto": "[email protected]",
"users_email_subject": "email subject",
"users_email_body": "Dear {name},\n\nthis is your personal OpenSlides login:\n\n{url}\nUsername: {username}\nPassword: {password}\n\n\nThis email was generated automatically.",
"require_duplicate_from": True,
"saml_enabled": True,
"saml_login_button_text": "Text for SAML login button",
"saml_attr_mapping": self.saml_attr_mapping,
Expand Down
3 changes: 3 additions & 0 deletions tests/system/presenter/test_check_database_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def test_correct(self) -> None:
"theme_ids": [1],
"committee_ids": [1],
"default_language": "en",
"require_duplicate_from": False,
"saml_enabled": False,
"saml_login_button_text": "Login button text",
},
Expand Down Expand Up @@ -311,6 +312,7 @@ def test_correct_relations(self) -> None:
"theme_ids": [1],
"committee_ids": [1],
"default_language": "en",
"require_duplicate_from": False,
"saml_enabled": True,
"saml_login_button_text": "SAML Login",
},
Expand Down Expand Up @@ -605,6 +607,7 @@ def test_relation_2(self) -> None:
"theme_ids": [1],
"committee_ids": [1],
"default_language": "en",
"require_duplicate_from": False,
"saml_enabled": True,
"saml_login_button_text": "SAML Login",
},
Expand Down