Skip to content

Commit

Permalink
chore: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinan029 committed Mar 27, 2024
2 parents b61b4e6 + 0e78b47 commit 1bfa117
Show file tree
Hide file tree
Showing 12 changed files with 337 additions and 21 deletions.
26 changes: 25 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@ Change Log
Unreleased
----------
[4.13.12]
---------
* feat: adding additional info to the enterprise group membership serializer

[4.13.11]
---------
* feat: pass force_enrollment when bulk enrolling learners

[4.13.10]
---------
* fix: remove filter to debug failing transmissions

[4.13.9]
---------
* fix: add missing filter to disable failing transmissions for 24hrs

[4.13.8]
---------
* feat: adding an activated_at value to group membership records

[4.13.7]
---------
* fix: adding get_queryset for fix of integrated channel api logs loading

[4.13.6]
---------
* feat: disable failing transmissions for 24hrs
Expand Down Expand Up @@ -65,7 +89,7 @@ Unreleased

[4.12.1]
---------
* feat: unlink canvas user if not decommissioned on canvas side
* feat: unlink canvas user if decommissioned on canvas side

[4.12.0]
---------
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.13.6"
__version__ = "4.13.12"
42 changes: 41 additions & 1 deletion enterprise/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,49 @@ class EnterpriseGroupMembershipSerializer(serializers.ModelSerializer):
enterprise_group_membership_uuid = serializers.UUIDField(source='uuid', allow_null=True, read_only=True)
enterprise_customer = EnterpriseCustomerSerializer(source='group.enterprise_customer', read_only=True)

member_details = serializers.SerializerMethodField()
recent_action = serializers.SerializerMethodField()
member_status = serializers.SerializerMethodField()

class Meta:
model = models.EnterpriseGroupMembership
fields = ('learner_id', 'pending_learner_id', 'enterprise_group_membership_uuid', 'enterprise_customer')
fields = (
'learner_id',
'pending_learner_id',
'enterprise_group_membership_uuid',
'member_details',
'recent_action',
'member_status',
'enterprise_customer'
)

def get_member_details(self, obj):
"""
Return either the member's name and email if it's the case that the member is realized, otherwise just email
"""
if user := obj.enterprise_customer_user:
return {"user_email": user.user_email, "user_name": user.name}
return {"user_email": obj.pending_enterprise_customer_user.user_email}

def get_recent_action(self, obj):
"""
Return the timestamp and name of the most recent action associated with the membership.
"""
if obj.is_removed:
return f"Removed: {obj.modified.strftime('%B %d, %Y')}"
if obj.enterprise_customer_user and obj.activated_at:
return f"Accepted: {obj.activated_at.strftime('%B %d, %Y')}"
return f"Invited: {obj.created.strftime('%B %d, %Y')}"

def get_member_status(self, obj):
"""
Return the status related to the membership.
"""
if obj.is_removed:
return "removed"
if obj.enterprise_customer_user:
return "accepted"
return "pending"


class EnterpriseCustomerUserReadOnlySerializer(serializers.ModelSerializer):
Expand Down
12 changes: 9 additions & 3 deletions enterprise/api/v1/views/enterprise_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,15 @@ def enroll_learners_in_courses(self, request, pk):
Parameters:
enrollments_info (list of dicts): an array of dictionaries, each containing the necessary information to
create an enrollment based on a subsidy for a user in a specified course. Each dictionary must contain
a user email (or user_id), a course run key, and either a UUID of the license that the learner is using
to enroll with or a transaction ID related to Executive Education the enrollment. `licenses_info` is
also accepted as a body param name.
the following keys:
* 'user_id' OR 'email': Either unique identifier describing the user to enroll.
* 'course_run_key': The course to enroll into.
* 'license_uuid' OR 'transaction_id': ID of either accepted form of subsidy. `license_uuid` refers to
subscription licenses, and `transaction_id` refers to Learner Credit transactions.
* 'force_enrollment' (bool, optional): Enroll even if enrollment deadline is expired (default False).
`licenses_info` is also accepted as a body param name.
Example::
Expand Down
2 changes: 2 additions & 0 deletions enterprise/api/v1/views/enterprise_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from enterprise.api.v1.views.base_views import EnterpriseReadWriteModelViewSet
from enterprise.logging import getEnterpriseLogger
from enterprise.tasks import send_group_membership_invitation_notification, send_group_membership_removal_notification
from enterprise.utils import localized_utcnow

LOGGER = getEnterpriseLogger(__name__)

Expand Down Expand Up @@ -200,6 +201,7 @@ def assign_learners(self, request, group_uuid):
# Extend the list of memberships that need to be created associated with existing Users
ent_customer_users = [
models.EnterpriseGroupMembership(
activated_at=localized_utcnow(),
enterprise_customer_user=ecu,
group=group
)
Expand Down
23 changes: 23 additions & 0 deletions enterprise/migrations/0203_auto_20240312_1527.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.23 on 2024-03-12 15:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('enterprise', '0202_enterprisegroup_applies_to_all_contexts_and_more'),
]

operations = [
migrations.AddField(
model_name='enterprisegroupmembership',
name='activated_at',
field=models.DateTimeField(blank=True, default=None, help_text='The moment at which the membership record is written with an Enterprise Customer User record.', null=True),
),
migrations.AddField(
model_name='historicalenterprisegroupmembership',
name='activated_at',
field=models.DateTimeField(blank=True, default=None, help_text='The moment at which the membership record is written with an Enterprise Customer User record.', null=True),
),
]
18 changes: 18 additions & 0 deletions enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,15 @@ def username(self):
return self.user.username
return None

@property
def name(self):
"""
Return linked user's name.
"""
if self.user is not None:
return f"{self.user.first_name} {self.user.last_name}"
return None

@property
def data_sharing_consent_records(self):
"""
Expand Down Expand Up @@ -1484,6 +1493,7 @@ def fulfill_pending_group_memberships(self, enterprise_customer_user):
enterprise_customer_user: a EnterpriseCustomerUser instance
"""
self.memberships.update(
activated_at=localized_utcnow(),
pending_enterprise_customer_user=None,
enterprise_customer_user=enterprise_customer_user
)
Expand Down Expand Up @@ -4310,6 +4320,14 @@ class EnterpriseGroupMembership(TimeStampedModel, SoftDeletableModel):
related_name='memberships',
on_delete=models.deletion.CASCADE,
)
activated_at = models.DateTimeField(
default=None,
blank=True,
null=True,
help_text=_(
"The moment at which the membership record is written with an Enterprise Customer User record."
),
)
history = HistoricalRecords()

class Meta:
Expand Down
7 changes: 6 additions & 1 deletion enterprise/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,7 @@ def customer_admin_enroll_user_with_status(
enrollment_source=None,
license_uuid=None,
transaction_id=None,
force_enrollment=False,
):
"""
For use with bulk enrollment, or any use case of admin enrolling a user
Expand Down Expand Up @@ -1848,6 +1849,7 @@ def customer_admin_enroll_user_with_status(
course_mode,
is_active=True,
enterprise_uuid=enterprise_customer.uuid,
force_enrollment=force_enrollment,
)
succeeded = True
LOGGER.info("Successfully enrolled user %s in course %s", user.id, course_id)
Expand Down Expand Up @@ -1987,6 +1989,7 @@ def enroll_subsidy_users_in_courses(enterprise_customer, subsidy_users_info, dis
* 'course_run_key': The course to enroll into.
* 'course_mode': The course mode.
* 'license_uuid' OR 'transaction_id': ID of either accepted form of subsidy.
* 'force_enrollment' (bool, optional): Enroll user even enrollment deadline is expired (default False).
Example::
Expand Down Expand Up @@ -2037,6 +2040,7 @@ def enroll_subsidy_users_in_courses(enterprise_customer, subsidy_users_info, dis
license_uuid = subsidy_user_info.get('license_uuid')
transaction_id = subsidy_user_info.get('transaction_id')
activation_link = subsidy_user_info.get('activation_link')
force_enrollment = subsidy_user_info.get('force_enrollment', False)

if user_id and user_email:
user = User.objects.filter(id=subsidy_user_info['user_id']).first()
Expand Down Expand Up @@ -2066,7 +2070,8 @@ def enroll_subsidy_users_in_courses(enterprise_customer, subsidy_users_info, dis
course_run_key,
enrollment_source,
license_uuid,
transaction_id
transaction_id,
force_enrollment=force_enrollment,
)
if succeeded:
success_dict = {
Expand Down
12 changes: 5 additions & 7 deletions integrated_channels/integrated_channel/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,10 @@ class IntegratedChannelAPIRequestLogAdmin(admin.ModelAdmin):

list_display = [
"endpoint",
"enterprise_customer",
"enterprise_customer_id",
"time_taken",
"status_code",
]
list_filter = [
"status_code",
"enterprise_customer",
"endpoint",
"time_taken",
]
search_fields = [
"status_code",
"enterprise_customer",
Expand All @@ -130,5 +124,9 @@ class IntegratedChannelAPIRequestLogAdmin(admin.ModelAdmin):

list_per_page = 20

def get_queryset(self, request):
queryset = super().get_queryset(request)
return queryset.select_related('enterprise_customer')

class Meta:
model = IntegratedChannelAPIRequestLogs
Loading

0 comments on commit 1bfa117

Please sign in to comment.