Explorar el Código

Merge pull request #2356 from nabinhait/hotfix

Cherry-picked "set last active time to user" from develop
version-14
Nabin Hait hace 8 años
committed by GitHub
padre
commit
9255c9589f
Se han modificado 3 ficheros con 34 adiciones y 2 borrados
  1. +24
    -0
      frappe/commands/site.py
  2. +6
    -2
      frappe/core/doctype/user/user.py
  3. +4
    -0
      frappe/utils/user.py

+ 24
- 0
frappe/commands/site.py Ver fichero

@@ -460,6 +460,29 @@ def clear_limits(context, site, limits):
if not limits: if not limits:
update_site_config('limits', 'None', validate=False) update_site_config('limits', 'None', validate=False)


@click.command('set-last-active-for-user')
@click.option('--user', help="Setup last active date for user")
@pass_context
def set_last_active_for_user(context, user=None):
"Set users last active date to current datetime"

from frappe.core.doctype.user.user import get_system_users
from frappe.utils.user import set_last_active_to_now
site = get_site(context)

with frappe.init_site(site):
frappe.connect()
if not user:
user = get_system_users(limit=1)
if len(user) > 0:
user = user[0]
else:
return

set_last_active_to_now(user)
frappe.db.commit()



commands = [ commands = [
add_system_manager, add_system_manager,
@@ -482,4 +505,5 @@ commands = [
clear_limits, clear_limits,
disable_user, disable_user,
_use, _use,
set_last_active_for_user,
] ]

+ 6
- 2
frappe/core/doctype/user/user.py Ver fichero

@@ -652,17 +652,21 @@ def get_total_users():
where enabled=1 and user_type="System User" where enabled=1 and user_type="System User"
and name not in ({})'''.format(", ".join(["%s"]*len(STANDARD_USERS))), STANDARD_USERS)[0][0] and name not in ({})'''.format(", ".join(["%s"]*len(STANDARD_USERS))), STANDARD_USERS)[0][0]


def get_system_users(exclude_users=None):
def get_system_users(exclude_users=None, limit=None):
if not exclude_users: if not exclude_users:
exclude_users = [] exclude_users = []
elif not isinstance(exclude_users, (list, tuple)): elif not isinstance(exclude_users, (list, tuple)):
exclude_users = [exclude_users] exclude_users = [exclude_users]
limit_cond = ''
if limit:
limit_cond = 'limit {0}'.format(limit)


exclude_users += list(STANDARD_USERS) exclude_users += list(STANDARD_USERS)


system_users = frappe.db.sql_list("""select name from `tabUser` system_users = frappe.db.sql_list("""select name from `tabUser`
where enabled=1 and user_type != 'Website User' where enabled=1 and user_type != 'Website User'
and name not in ({})""".format(", ".join(["%s"]*len(exclude_users))),
and name not in ({}) {}""".format(", ".join(["%s"]*len(exclude_users)), limit_cond),
exclude_users) exclude_users)


return system_users return system_users


+ 4
- 0
frappe/utils/user.py Ver fichero

@@ -305,3 +305,7 @@ def get_users():
}) })


return users return users

def set_last_active_to_now(user):
from frappe.utils import now_datetime
frappe.db.set_value("User", user, "last_active", now_datetime())

Cargando…
Cancelar
Guardar