Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
124 lines
4.3 KiB
Python
124 lines
4.3 KiB
Python
from django.utils.translation import gettext as _
|
|
|
|
from zerver.lib.exceptions import JsonableError
|
|
from zerver.lib.types import UserGroupMembersData
|
|
from zerver.lib.user_groups import (
|
|
check_group_membership_management_permissions_with_admins_only,
|
|
get_recursive_subgroups,
|
|
get_recursive_subgroups_for_groups,
|
|
get_role_based_system_groups_dict,
|
|
get_user_group_by_id_in_realm,
|
|
)
|
|
from zerver.models import NamedUserGroup, Realm
|
|
|
|
|
|
def validate_workplace_users_group(
|
|
workplace_users_group: int | UserGroupMembersData, realm: Realm
|
|
) -> None:
|
|
system_groups_name_dict = get_role_based_system_groups_dict(realm)
|
|
if isinstance(workplace_users_group, int):
|
|
group = get_user_group_by_id_in_realm(workplace_users_group, realm, for_read=True)
|
|
if group.is_system_group:
|
|
# System group memberships can only change when a user's role
|
|
# changes, which only admins can do.
|
|
return
|
|
|
|
workplace_users_group_subgroups = get_recursive_subgroups_for_groups(
|
|
[workplace_users_group], realm
|
|
)
|
|
else:
|
|
subgroup_ids = workplace_users_group.direct_subgroups
|
|
subgroups = NamedUserGroup.objects.filter(id__in=subgroup_ids, realm_for_sharding=realm)
|
|
non_system_group_subgroup_ids = [
|
|
subgroup.id for subgroup in subgroups if not subgroup.is_system_group
|
|
]
|
|
if len(non_system_group_subgroup_ids) == 0:
|
|
# All direct subgroups are system groups, whose memberships can
|
|
# only change when a user's role changes, which only admins can do.
|
|
return
|
|
|
|
workplace_users_group_subgroups = get_recursive_subgroups_for_groups(
|
|
non_system_group_subgroup_ids, realm
|
|
)
|
|
|
|
if not check_group_membership_management_permissions_with_admins_only(
|
|
list(workplace_users_group_subgroups), realm, system_groups_name_dict
|
|
):
|
|
raise JsonableError(
|
|
_(
|
|
"'workplace_users_group' must be a group whose membership can only be managed by organization administrators."
|
|
)
|
|
)
|
|
|
|
|
|
def realm_eligible_for_non_workplace_pricing(realm: Realm) -> bool:
|
|
if realm.plan_type == Realm.PLAN_TYPE_SELF_HOSTED:
|
|
# Non-workplace plan pricing is not yet implemented
|
|
# for self-hosted plans.
|
|
return False
|
|
|
|
if realm.plan_type == Realm.PLAN_TYPE_STANDARD_FREE:
|
|
# Fully sponsored plans are completely free, so it
|
|
# would be distracting to offer menu options for
|
|
# discounted pricing.
|
|
return False
|
|
|
|
if realm.plan_type == Realm.PLAN_TYPE_LIMITED:
|
|
# We want to allow organizations to enable discounted
|
|
# pricing for non workplace users before they upgrade.
|
|
return True
|
|
|
|
from corporate.models.plans import get_current_plan_by_realm
|
|
|
|
customer_plan = get_current_plan_by_realm(realm)
|
|
|
|
if customer_plan is None:
|
|
# Support staff have manually set a paid plan type for
|
|
# this realm, and we want them to be able to correctly
|
|
# configure their billing.
|
|
return True
|
|
|
|
if customer_plan.fixed_price is not None:
|
|
# Discounted pricing for non-workplace users is
|
|
# currently incompatible with a fixed-price plan.
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
def realm_on_discounted_cloud_plan(realm: Realm) -> bool:
|
|
if realm.plan_type == Realm.PLAN_TYPE_SELF_HOSTED:
|
|
return False
|
|
|
|
if realm.plan_type in {Realm.PLAN_TYPE_LIMITED, Realm.PLAN_TYPE_STANDARD_FREE}:
|
|
# Realm is on free plan or is fully sponsored.
|
|
return False
|
|
|
|
from corporate.models.customers import get_customer_by_realm
|
|
|
|
customer = get_customer_by_realm(realm)
|
|
|
|
if customer is None:
|
|
# Support staff have manually set a paid plan type for
|
|
# this realm.
|
|
return False
|
|
|
|
return customer.monthly_discounted_price > 0 or customer.annual_discounted_price > 0
|
|
|
|
|
|
def check_any_group_used_for_workplace_users_group(
|
|
realm: Realm, user_groups: list[NamedUserGroup]
|
|
) -> bool:
|
|
user_group_ids = {group.id for group in user_groups}
|
|
|
|
if realm.workplace_users_group_id in user_group_ids:
|
|
return True
|
|
|
|
workplace_users_group_subgroup_ids = set(
|
|
get_recursive_subgroups(realm.workplace_users_group_id).values_list("id", flat=True)
|
|
)
|
|
if workplace_users_group_subgroup_ids & user_group_ids:
|
|
return True
|
|
|
|
return False
|