Skip to content

Commit

Permalink
add admin action
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomm19 committed Nov 9, 2023
1 parent 6137a25 commit f68b155
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion breathecode/authenticate/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.contrib.admin import SimpleListFilter
from breathecode.utils.datetime_integer import from_now
from django.db.models import QuerySet, Q
import breathecode.marketing.actions as marketing_actions
from . import tasks

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -96,14 +97,22 @@ def accept_all_users_from_waiting_list(modeladmin, request, queryset: QuerySet[U
tasks.async_accept_user_from_waiting_list.delay(x.id)


def validate_email(modeladmin, request, queryset: QuerySet[UserInvite]):
for x in queryset:
email_status = marketing_actions.validate_email(x.email, 'en')
x.email_quality = email_status['score']
x.email_status = email_status
x.save()


@admin.register(UserInvite)
class UserInviteAdmin(admin.ModelAdmin):
search_fields = ['email', 'first_name', 'last_name', 'user__email']
raw_id_fields = ['user', 'author', 'cohort']
list_filter = ['academy', 'status', 'is_email_validated', 'process_status', 'role', 'country']
list_display = ('email', 'is_email_validated', 'first_name', 'last_name', 'status', 'academy', 'token',
'created_at', 'invite_url', 'country')
actions = [accept_selected_users_from_waiting_list, accept_all_users_from_waiting_list]
actions = [accept_selected_users_from_waiting_list, accept_all_users_from_waiting_list, validate_email]

def invite_url(self, obj):
params = {'callback': 'https://4geeks.com'}
Expand Down
6 changes: 6 additions & 0 deletions breathecode/authenticate/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from breathecode.events.models import Event
from breathecode.registry.models import Asset
import breathecode.activity.tasks as tasks_activity
from breathecode.marketing.actions import validate_email

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1476,6 +1477,11 @@ def get_access_token(self, obj: UserInvite):
if obj.status != 'ACCEPTED':
return None

email_status = validate_email(obj.email, lang)
obj.email_quality = email_status['score']
obj.email_status = email_status
obj.save()

if not self.user:
self.user = User(email=obj.email,
username=obj.email,
Expand Down

0 comments on commit f68b155

Please sign in to comment.