feat: allow created a session for a fixed duration via bench browse
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
bea4dc68fe
commit
a121b90d7f
3 changed files with 14 additions and 3 deletions
|
|
@ -219,7 +219,10 @@ class LoginManager:
|
|||
def make_session(self, resume=False):
|
||||
# start session
|
||||
frappe.local.session_obj = Session(
|
||||
user=self.user, resume=resume, full_name=self.full_name, user_type=self.user_type
|
||||
user=self.user,
|
||||
resume=resume,
|
||||
full_name=self.full_name,
|
||||
user_type=self.user_type,
|
||||
)
|
||||
|
||||
# reset user if changed to Guest
|
||||
|
|
|
|||
|
|
@ -1175,8 +1175,9 @@ def publish_realtime(context: CliCtxObj, event, message, room, user, doctype, do
|
|||
@click.command("browse")
|
||||
@click.argument("site", required=False)
|
||||
@click.option("--user", required=False, help="Login as user")
|
||||
@click.option("--duration", required=False, help="Session duration (in hh:mm:ss format)")
|
||||
@pass_context
|
||||
def browse(context: CliCtxObj, site, user=None):
|
||||
def browse(context: CliCtxObj, site, user=None, duration=None):
|
||||
"""Opens the site on web browser"""
|
||||
from frappe.auth import CookieManager, LoginManager
|
||||
|
||||
|
|
@ -1192,6 +1193,8 @@ def browse(context: CliCtxObj, site, user=None):
|
|||
frappe.init(site)
|
||||
frappe.connect()
|
||||
|
||||
frappe.flags.session_duration = duration
|
||||
|
||||
sid = ""
|
||||
if user:
|
||||
if not frappe.db.exists("User", user):
|
||||
|
|
|
|||
|
|
@ -246,11 +246,13 @@ class Session:
|
|||
self.sid = self.data.sid = sid
|
||||
self.data.data.user = self.user
|
||||
self.data.data.session_ip = frappe.local.request_ip
|
||||
if frappe.flags.session_duration:
|
||||
self.data.data.fixed_duration = True
|
||||
if self.user != "Guest":
|
||||
self.data.data.update(
|
||||
{
|
||||
"last_updated": frappe.utils.now(),
|
||||
"session_expiry": get_expiry_period(),
|
||||
"session_expiry": frappe.flags.session_duration or get_expiry_period(),
|
||||
"full_name": self.full_name,
|
||||
"user_type": self.user_type,
|
||||
}
|
||||
|
|
@ -386,6 +388,9 @@ class Session:
|
|||
if frappe.session.user == "Guest":
|
||||
return
|
||||
|
||||
if self.data.data.fixed_duration:
|
||||
return
|
||||
|
||||
now = frappe.utils.now_datetime()
|
||||
|
||||
# update session in db
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue