[fix] dissable additiona users by creation date
This commit is contained in:
parent
8443debfdf
commit
86ebaf22aa
3 changed files with 19 additions and 2 deletions
|
|
@ -416,6 +416,7 @@ def _set_limits(context, site, limits):
|
|||
site = get_site(context)
|
||||
|
||||
with frappe.init_site(site):
|
||||
frappe.connect()
|
||||
new_limits = {}
|
||||
for limit, value in limits:
|
||||
if limit not in ('emails', 'space', 'users', 'email_group',
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from frappe import _
|
|||
from frappe.utils import now_datetime, getdate, flt, cint, get_fullname
|
||||
from frappe.installer import update_site_config
|
||||
from frappe.utils.data import formatdate
|
||||
from frappe.utils.user import get_enabled_system_users
|
||||
from frappe.utils.user import get_enabled_system_users, disable_users
|
||||
import os, subprocess, urlparse, urllib
|
||||
|
||||
class SiteExpiredError(frappe.ValidationError):
|
||||
|
|
@ -149,6 +149,7 @@ def update_limits(limits_dict):
|
|||
limits = get_limits()
|
||||
limits.update(limits_dict)
|
||||
update_site_config("limits", limits, validate=False)
|
||||
disable_users(limits)
|
||||
frappe.local.conf.limits = limits
|
||||
|
||||
def clear_limit(key):
|
||||
|
|
|
|||
|
|
@ -308,4 +308,19 @@ def get_users():
|
|||
|
||||
def set_last_active_to_now(user):
|
||||
from frappe.utils import now_datetime
|
||||
frappe.db.set_value("User", user, "last_active", now_datetime())
|
||||
frappe.db.set_value("User", user, "last_active", now_datetime())
|
||||
|
||||
def disable_users(limits=None):
|
||||
if not limits:
|
||||
return
|
||||
|
||||
if limits.get('users'):
|
||||
active_users = frappe.db.sql_list("""select name from tabUser
|
||||
where name not in ('Administrator', 'Guest') and user_type = 'System User' and enabled=1
|
||||
order by creation desc""")
|
||||
|
||||
if len(active_users) > limits.get('users'):
|
||||
for user in active_users[: -limits.get('users')]:
|
||||
frappe.db.set_value("User", user, 'enabled', 0)
|
||||
|
||||
frappe.db.commit()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue