Skip to content

Commit

Permalink
add email notification opt-out settings (#1417)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Apr 23, 2024
1 parent 6ace1aa commit 52837dc
Show file tree
Hide file tree
Showing 7 changed files with 1,016 additions and 550 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Added
- ``checkusers`` management command (#1410)
- ``SODARPageNumberPagination`` pagination class (#1313)
- Optional pagination for REST API list views (#1313)
- Email notification opt-out settings (#1417)
- **Timeline**
- ``sodar_uuid`` field in ``TimelineEventObjectRef`` model (#1415)
- REST API views (#1350)
Expand Down
6 changes: 6 additions & 0 deletions docs/source/app_userprofile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ Display Project UUID Copying Link
Additional Email
In addition to the default user email, also send email notifications to
these addresses.
Receive Email for Project Updates
Receive email notifications for project or category creation, updating,
moving and archiving.
Receive Email for Project Membership Updates
Receive email notifications for project or category membership updates and
invitation activity.

In the development setup, the SODAR Core example site apps also provide
additional settings for demonstrating settings features.
3 changes: 2 additions & 1 deletion docs/source/major_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ Release Highlights
==================

- Upgrade to Django v4.2 and Postgres v16
- Add Python v3.11 support
- Add app specific and semantic REST API versioning
- Add REST API versioning independent from repo/site versions
- Add Python v3.11 support
- Add timeline REST API
- Add optional pagination for REST API list views
- Add user opt-out settings for email notifications
- Add target site user UUID updating in remote sync
- Add remote sync of existing target local users
- Add remote sync of USER scope app settings
Expand Down
35 changes: 35 additions & 0 deletions projectroles/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from projectroles.models import AppSetting, APP_SETTING_TYPES, SODAR_CONSTANTS
from projectroles.plugins import get_app_plugin, get_active_plugins
from projectroles.utils import get_display_name


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -116,6 +117,40 @@
'global': False,
'project_types': [PROJECT_TYPE_PROJECT, PROJECT_TYPE_CATEGORY],
},
'notify_email_project': {
'scope': APP_SETTING_SCOPE_USER,
'type': 'BOOLEAN',
'default': True,
'label': 'Receive email for {} updates'.format(
get_display_name(PROJECT_TYPE_PROJECT)
),
'description': (
'Receive email notifications for {} or {} creation, updating, '
'moving and archiving.'.format(
get_display_name(PROJECT_TYPE_CATEGORY),
get_display_name(PROJECT_TYPE_PROJECT),
)
),
'user_modifiable': True,
'global': True,
},
'notify_email_role': {
'scope': APP_SETTING_SCOPE_USER,
'type': 'BOOLEAN',
'default': True,
'label': 'Receive email for {} membership updates'.format(
get_display_name(PROJECT_TYPE_PROJECT)
),
'description': (
'Receive email notifications for {} or {} membership updates and '
'invitation activity.'.format(
get_display_name(PROJECT_TYPE_CATEGORY),
get_display_name(PROJECT_TYPE_PROJECT),
)
),
'user_modifiable': True,
'global': True,
},
}


Expand Down
8 changes: 7 additions & 1 deletion projectroles/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
SITE_TITLE = settings.SITE_INSTANCE_TITLE

# Local constants
APP_NAME = 'projectroles'
EMAIL_RE = re.compile(r'(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)')


Expand Down Expand Up @@ -673,7 +674,12 @@ def send_project_archive_mail(project, action, request):
:return: Amount of sent email (int)
"""
user = request.user
project_users = [a.user for a in project.get_roles() if a.user != user]
project_users = [
a.user
for a in project.get_roles()
if a.user != user
and app_settings.get(APP_NAME, 'notify_email_project', user=a.user)
]
project_users = list(set(project_users)) # Remove possible dupes (see #710)
if not project_users:
return 0
Expand Down
Loading

0 comments on commit 52837dc

Please sign in to comment.