Membership: release service groups without revoking; Harmony on the members page
- MEMBERSHIP_RELEASED_GROUPS_JSON: DNs the service stops managing. Every account's record of them is dropped before reconciliation, so members keep their current membership and nobody new is granted it. Validated as DNs, unique, and not also a tier or service group. - Harmony Users shows as "Harmony · chat, voice and video", linked. - Copy: members connect on Discourse, Harmony and Mastodon; Bronze exclusive content is on Discourse and Harmony. Tests: 203 run; the one error (test_published_tier_copy_matches_role_defaults cannot find tiers.eom.json in the test image) is pre-existing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -160,3 +160,12 @@ try:
|
||||
except (ValueError, OSError):
|
||||
raise ImproperlyConfigured("Cannot load membership service group configuration.") from None
|
||||
MEMBERSHIP_SERVICE_GROUPS = validate_service_groups(service_groups, levels)
|
||||
|
||||
# Groups no longer managed here: dropped from every account's records, never revoked.
|
||||
from members.service_groups import validate_released_groups
|
||||
|
||||
try:
|
||||
released_groups = json.loads(os.environ.get("MEMBERSHIP_RELEASED_GROUPS_JSON", "[]"))
|
||||
except ValueError:
|
||||
raise ImproperlyConfigured("MEMBERSHIP_RELEASED_GROUPS_JSON must be a JSON list of LDAP group DNs.") from None
|
||||
MEMBERSHIP_RELEASED_GROUPS = validate_released_groups(released_groups, MEMBERSHIP_TIERS, MEMBERSHIP_SERVICE_GROUPS)
|
||||
|
||||
@@ -105,6 +105,11 @@ def apply_groups(account):
|
||||
# Compute from paid time on this pass, never the cached account level or
|
||||
# Dex claims. Level 0 is selected only when no paid entitlement remains.
|
||||
desired.update(settings.MEMBERSHIP_SERVICE_GROUPS.get(str(membership_level), []))
|
||||
# Released groups are forgotten, not revoked: members keep what they have.
|
||||
released = {dn.casefold() for dn in settings.MEMBERSHIP_RELEASED_GROUPS}
|
||||
if released:
|
||||
stale = [group.pk for group in ManagedGroup.objects.filter(account=account) if group.dn.casefold() in released]
|
||||
ManagedGroup.objects.filter(pk__in=stale).delete()
|
||||
managed = set(ManagedGroup.objects.filter(account=account).values_list("dn", flat=True))
|
||||
account.ldap_dn = reconcile_groups(account, desired, managed) if managed else account.ldap_dn
|
||||
account.last_ldap_sync = now
|
||||
|
||||
@@ -28,6 +28,10 @@ SERVICE_LINKS = {
|
||||
"url": "https://peertube.eom.dev/",
|
||||
"favicon": "https://peertube.eom.dev/client/assets/images/favicon.png",
|
||||
},
|
||||
"Harmony · chat, voice and video": {
|
||||
"url": "https://harmony.eom.dev/",
|
||||
"favicon": "https://harmony.eom.dev/favicon.ico",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +58,32 @@ def validate_service_groups(value, paid_levels):
|
||||
return value
|
||||
|
||||
|
||||
def validate_released_groups(value, tiers, service_groups):
|
||||
"""Groups this service stops managing without revoking anyone's access.
|
||||
|
||||
Every account's record of a released DN is dropped before reconciliation,
|
||||
so members keep the membership they have and nobody new is granted it.
|
||||
A released DN may not also be configured: that would grant and forget it.
|
||||
"""
|
||||
if not isinstance(value, list):
|
||||
raise ImproperlyConfigured("Released service groups must be a list of LDAP group DNs.")
|
||||
configured = {dn.casefold() for dn in configured_groups(tiers, service_groups)}
|
||||
seen = set()
|
||||
for dn in value:
|
||||
if not isinstance(dn, str) or not dn or dn != dn.strip() or len(dn) > 1024 or any(ord(char) < 32 for char in dn):
|
||||
raise ImproperlyConfigured("Released group DNs must be nonempty valid LDAP DNs of at most 1024 characters.")
|
||||
try:
|
||||
parts = parse_dn(dn)
|
||||
except LDAPInvalidDnError:
|
||||
raise ImproperlyConfigured("Invalid released LDAP group DN.") from None
|
||||
if not parts or dn.casefold() in seen:
|
||||
raise ImproperlyConfigured("Released group DNs must be valid and unique.")
|
||||
if dn.casefold() in configured:
|
||||
raise ImproperlyConfigured("A released group cannot also be a tier or service group.")
|
||||
seen.add(dn.casefold())
|
||||
return value
|
||||
|
||||
|
||||
def configured_groups(tiers, service_groups):
|
||||
"""All managed targets, not only the groups this account currently earns."""
|
||||
return {tier["group_dn"] for tier in tiers.values()} | {
|
||||
@@ -70,6 +100,7 @@ def service_names(level, service_groups):
|
||||
"matrix users": "Matrix · community chat",
|
||||
"mastodon users": "Mastodon · social networking",
|
||||
"peertube users": "PeerTube · video sharing",
|
||||
"harmony users": "Harmony · chat, voice and video",
|
||||
}
|
||||
names = []
|
||||
for dn in service_groups.get(str(level), []):
|
||||
|
||||
@@ -547,3 +547,46 @@ class ServiceGroupDurabilityTests(ServiceGroupFixture, TransactionTestCase):
|
||||
self.ldap.side_effect = None
|
||||
with override_settings(MEMBERSHIP_TIERS={}, MEMBERSHIP_SERVICE_GROUPS={"0": [FREE_GROUP]}):
|
||||
self.assert_sync({FREE_GROUP}, 0)
|
||||
|
||||
@override_settings(MEMBERSHIP_TIERS=TIERS, MEMBERSHIP_SERVICE_GROUPS=SERVICE_GROUPS)
|
||||
class ReleasedGroupTests(ServiceGroupFixture, TestCase):
|
||||
"""Released groups are forgotten for every account and never revoked."""
|
||||
|
||||
def test_released_group_is_forgotten_not_revoked(self):
|
||||
ManagedGroup.objects.create(account=self.member, dn=HISTORICAL_GROUP)
|
||||
with override_settings(MEMBERSHIP_RELEASED_GROUPS=[HISTORICAL_GROUP]):
|
||||
self.assert_sync({FREE_GROUP}, 0)
|
||||
self.assertNotIn(HISTORICAL_GROUP, self.managed_groups())
|
||||
|
||||
def test_release_matches_dns_case_insensitively(self):
|
||||
ManagedGroup.objects.create(account=self.member, dn=HISTORICAL_GROUP.upper())
|
||||
with override_settings(MEMBERSHIP_RELEASED_GROUPS=[HISTORICAL_GROUP]):
|
||||
self.assert_sync({FREE_GROUP}, 0)
|
||||
|
||||
def test_unreleased_historical_group_is_still_revoked(self):
|
||||
ManagedGroup.objects.create(account=self.member, dn=HISTORICAL_GROUP)
|
||||
with override_settings(MEMBERSHIP_RELEASED_GROUPS=["cn=other-retired," + BASE]):
|
||||
self.assert_sync({FREE_GROUP}, 0, managed=ALL_GROUPS | {HISTORICAL_GROUP})
|
||||
|
||||
def test_released_groups_must_be_valid_unique_and_unconfigured(self):
|
||||
from members.service_groups import validate_released_groups
|
||||
self.assertEqual(validate_released_groups([HISTORICAL_GROUP], TIERS, SERVICE_GROUPS), [HISTORICAL_GROUP])
|
||||
for value in ({}, [""], [" " + HISTORICAL_GROUP], ["not a dn"], [HISTORICAL_GROUP, HISTORICAL_GROUP.upper()], [FREE_GROUP], [TIER_GROUP.upper()]):
|
||||
with self.subTest(value=value), self.assertRaises(ImproperlyConfigured):
|
||||
validate_released_groups(value, TIERS, SERVICE_GROUPS)
|
||||
|
||||
def test_settings_load_released_groups_json(self):
|
||||
environment = {
|
||||
"MEMBERSHIP_TIERS_JSON": json.dumps(TIERS),
|
||||
"MEMBERSHIP_SERVICE_GROUPS_JSON": json.dumps(SERVICE_GROUPS),
|
||||
"MEMBERSHIP_RELEASED_GROUPS_JSON": json.dumps([HISTORICAL_GROUP]),
|
||||
}
|
||||
with patch.dict(os.environ, environment):
|
||||
loaded = runpy.run_path(str(Path(__file__).absolute().parents[2] / "config" / "settings.py"))
|
||||
self.assertEqual(loaded["MEMBERSHIP_RELEASED_GROUPS"], [HISTORICAL_GROUP])
|
||||
environment["MEMBERSHIP_RELEASED_GROUPS_JSON"] = json.dumps([FREE_GROUP])
|
||||
with patch.dict(os.environ, environment), self.assertRaises(ImproperlyConfigured):
|
||||
runpy.run_path(str(Path(__file__).absolute().parents[2] / "config" / "settings.py"))
|
||||
|
||||
def test_harmony_has_a_public_label(self):
|
||||
self.assertEqual(service_names(0, {"0": ["cn=Harmony Users,ou=Harmony,ou=Services,dc=eom,dc=dev"]}), ["Harmony · chat, voice and video"])
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
<details><summary>How do membership giveaways work?</summary><p>Giveaways are associated with a membership tier. Higher tiers include giveaway benefits from lower tiers, including Open Lab. Each giveaway's rules will list its availability, dates, prizes and any eligibility restrictions. Membership does not guarantee a prize.</p></details>
|
||||
<details><summary>What do membership polls influence?</summary><p>Gold (Level 3) and above can share preferences about future project topics and experiments. Platinum (Level 4) and Diamond (Level 5) also receive separate polls about the direction of eom.dev itself. Results inform my decisions; they are not binding commitments or guarantees of particular features.</p></details>
|
||||
<details><summary>What happens when a membership ends?</summary><p>Your free eom.dev account stays. Member-only access ends when your paid membership expires. An immediate cancellation removes that access once your membership status updates.</p></details>
|
||||
<details><summary>Where do members connect?</summary><p>On Discourse and Matrix. Ordinary community access is free; Bronze and above also receive exclusive content in those services.</p></details>
|
||||
<details><summary>Where do members connect?</summary><p>On Discourse, Harmony and Mastodon, which come with every membership level, including the free one. Bronze and above also receive exclusive content on Discourse and Harmony.</p></details>
|
||||
<details><summary>Can I change or cancel a plan?</summary><p>Use Manage billing after signing in. The billing portal offers the changes enabled for your plan. Cancellation at period end keeps access through the paid expiry date.</p></details>
|
||||
{% if shkeeper_enabled %}<details><summary>How do crypto memberships renew?</summary><p>SHKeeper payments prepay one calendar month, without automatic charges. Create a new invoice for each renewal. Confirmed payment on the same tier extends its prepaid term. Partial or unconfirmed payments do not grant access. Do not send renewal funds to an old invoice address.</p></details>{% endif %}
|
||||
</section>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"group_dn": "cn=Level 1,ou=Memberships,dc=eom,dc=dev",
|
||||
"description": "Go beyond the public feed.",
|
||||
"benefits": [
|
||||
"Exclusive Discourse and Matrix content, including work-in-progress updates",
|
||||
"Exclusive Discourse and Harmony content, including work-in-progress updates",
|
||||
"Bronze-tier giveaways",
|
||||
"Optional credit on the community supporters page"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user