Skip to content

Commit

Permalink
notify org admin when user froze
Browse files Browse the repository at this point in the history
  • Loading branch information
likesclever committed Dec 4, 2023
1 parent 7b3ca29 commit 2e19b96
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion seahub/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def login(request, template_name='registration/login.html',
try:
user = User.objects.get(email)
if user.is_active:
user.freeze_user(notify_admins=True)
user.freeze_user(notify_admins=True, notify_org_admins=True)
logger.warn('Login attempt limit reached, freeze the user email/username: %s, ip: %s, attemps: %d' %
(login, ip, failed_attempt))
except User.DoesNotExist:
Expand Down
33 changes: 32 additions & 1 deletion seahub/base/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def email_user(self, subject, message, from_email=None):
"Sends an e-mail to this User."
send_mail(subject, message, from_email, [self.email])

def freeze_user(self, notify_admins=False):
def freeze_user(self, notify_admins=False, notify_org_admins=False):
self.is_active = False
self.save()

Expand All @@ -492,6 +492,37 @@ def freeze_user(self, notify_admins=False):
# restore current language
translation.activate(cur_language)

if notify_org_admins:
org = None
if is_pro_version():
orgs = ccnet_api.get_orgs_by_user(self.username)
if orgs:
org = orgs[0]

org_members = list()
if org:
org_members = ccnet_api.get_org_emailusers(org.url_prefix, -1, -1)
for u in org_members:
if not (ccnet_api.is_org_staff(org.org_id, u.email) == 1):
continue

# save current language
cur_language = translation.get_language()

# get and active user language
user_language = Profile.objects.get_user_language(u.email)
translation.activate(user_language)

send_html_email_with_dj_template(u.email,
subject=_('Account %(account)s froze on %(site)s.') % {
"account": self.email,
"site": get_site_name()},
dj_template='sysadmin/user_freeze_email.html',
context={'user': self.email})

# restore current language
translation.activate(cur_language)

def remove_repo_passwds(self):
"""
Remove all repo decryption passwords stored on server.
Expand Down

0 comments on commit 2e19b96

Please sign in to comment.