1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-26 15:26:19 +00:00

org operation signal (#8120)

This commit is contained in:
lian
2025-08-19 16:33:58 +08:00
committed by GitHub
parent 8a7b06ff3f
commit c0a10a4c71
4 changed files with 17 additions and 16 deletions

View File

@@ -1,22 +1,16 @@
import os import os
import sys import sys
import logging import logging
from seahub.organizations.signals import org_created, org_reactivated from seahub.organizations.signals import org_operation_signal
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
try: try:
conf_dir = os.environ['SEAFILE_CENTRAL_CONF_DIR'] conf_dir = os.environ['SEAFILE_CENTRAL_CONF_DIR']
sys.path.append(conf_dir) sys.path.append(conf_dir)
try: try:
from seahub_custom_functions import org_created_callback from seahub_custom_functions import org_operation_callback
org_created.connect(org_created_callback) org_operation_signal.connect(org_operation_callback)
except ImportError as e: except ImportError as e:
logger.debug(e) logger.error(e)
try:
from seahub_custom_functions import org_reactivated_callback
org_reactivated.connect(org_reactivated_callback)
except ImportError as e:
logger.debug(e)
except KeyError as e: except KeyError as e:
logger.debug(e) logger.error(e)

View File

@@ -10,6 +10,7 @@ from seahub.constants import DEFAULT_ORG
from seahub.role_permissions.utils import get_available_roles from seahub.role_permissions.utils import get_available_roles
from seahub.avatar.util import get_avatar_file_storage from seahub.avatar.util import get_avatar_file_storage
from seahub.avatar.settings import AVATAR_STORAGE_DIR from seahub.avatar.settings import AVATAR_STORAGE_DIR
from seahub.organizations.signals import org_operation_signal
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -88,6 +89,11 @@ class OrgSettingsManager(models.Manager):
if is_active is not None: if is_active is not None:
settings.is_active = is_active settings.is_active = is_active
try:
org_operation_signal.send(sender=None, org=org,
operation='active' if is_active else 'inactive')
except Exception as e:
logger.error(e)
settings.save(using=self._db) settings.save(using=self._db)
return settings return settings

View File

@@ -2,6 +2,5 @@
from django.dispatch import Signal from django.dispatch import Signal
# A new org is created # A new org is created
org_created = Signal() org_operation_signal = Signal()
org_reactivated = Signal()
org_last_activity = Signal() org_last_activity = Signal()

View File

@@ -28,7 +28,7 @@ from seahub.utils import get_service_url, render_error
from seahub.utils.auth import get_login_bg_image_path from seahub.utils.auth import get_login_bg_image_path
from seahub.organizations.models import OrgSettings from seahub.organizations.models import OrgSettings
from seahub.organizations.signals import org_created, org_reactivated from seahub.organizations.signals import org_operation_signal
from seahub.organizations.decorators import org_staff_required from seahub.organizations.decorators import org_staff_required
from seahub.organizations.forms import OrgRegistrationForm from seahub.organizations.forms import OrgRegistrationForm
from seahub.organizations.settings import ORG_AUTO_URL_PREFIX, \ from seahub.organizations.settings import ORG_AUTO_URL_PREFIX, \
@@ -253,7 +253,10 @@ def org_register(request):
create_org(org_name, url_prefix, new_user.username) create_org(org_name, url_prefix, new_user.username)
new_org = get_org_by_url_prefix(url_prefix) new_org = get_org_by_url_prefix(url_prefix)
org_created.send(sender=None, email=email, org=new_org) try:
org_operation_signal.send(sender=None, org=new_org, operation='create')
except Exception as e:
logger.error(e)
if name: if name:
Profile.objects.add_or_update(new_user.username, name) Profile.objects.add_or_update(new_user.username, name)
@@ -360,5 +363,4 @@ def org_reactivate(request, token):
invite.accept() invite.accept()
OrgSettings.objects.add_or_update(org, is_active=True) OrgSettings.objects.add_or_update(org, is_active=True)
org_reactivated.send(sender=None, email=None, org=org)
return HttpResponseRedirect(settings.SITE_ROOT) return HttpResponseRedirect(settings.SITE_ROOT)