Skip to content

Commit

Permalink
Update to 1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
kid1194 committed Oct 9, 2023
1 parent dde80c6 commit 4907a80
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 49 deletions.
2 changes: 1 addition & 1 deletion active_users/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# Licence: Please refer to LICENSE file


__version__ = "1.0.8"
__version__ = "1.0.9"
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,60 @@ frappe.provide('frappe._active_users');

frappe.ui.form.on('Active Users Settings', {
setup: function(frm) {
frm.AU = {
update_messages: [
__('No new version is found'),
frm._visibility_ready = false;
frm._update = {
ready: false,
messages: [
__('App is up to date'),
__('A new version is available'),
],
update_tags: ['span', 'strong'],
update_classes: ['text-muted', 'text-danger'],
tags: ['span', 'strong'],
classes: ['text-muted', 'text-danger'],
};
},
refresh: function(frm) {
let idx = cint(frm.doc.has_update);
frm.get_field('update_note').$wrapper.html(
'<' + frm.AU.update_tags[idx]
+ 'class="' + frm.AU.update_classes[idx] + '">'
+ frm.AU.update_messages[idx]
+ '</' + frm.AU.update_tags[idx] + '>'
);
if (!frm._visibility_ready) {
frm._visibility_ready = true;
frm.get_field('visibility_note').$wrapper.html(
'<div class="font-weight-bold mb-1">' + __('Note') + ':</div>'
+ '<ul>'
+ '<li>'
+ __(
'If the user has any of the listed {0}, '
+ 'then the visibility of the plugin will depend on the '
+ 'status of the {1} checkbox.',
[
'<code>' + __('Roles') + '</code>',
'<code>' + __('Hidden From Listed Roles') + '</code>'
]
)
+ '</li>'
+ '<li class="mt-1">'
+ __(
'If the user exists in the listed {0}, '
+ 'then the visibility of the plugin will '
+ 'depend on the status of the {1} checkbox, '
+ 'bypassing the visibility status of listed {2}.',
[
'<code>' + __('Users') + '</code>',
'<code>' + __('Hidden From Listed Users') + '</code>',
'<code>' + __('Roles') + '</code>'
]
)
+ '</li>'
+ '</ul>'
);
}
if (!frm._update.ready) {
frm._update.ready = true;
let idx = cint(frm.doc.has_update);
frm.get_field('update_note').$wrapper.html(
'<' + frm._update.tags[idx]
+ 'class="' + frm._update.classes[idx] + '">'
+ frm._update.messages[idx]
+ '</' + frm._update.tags[idx] + '>'
);
}
},
check_for_update: function(frm) {
if (frappe._active_users._init)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"fieldname": "visibility_note",
"fieldtype": "HTML",
"label": "",
"options": "<div class=\"font-weight-bold mb-1\">Note:</div>\n<ul>\n<li>\nIf the user has any of the listed <code>Roles</code>, then the visibility of the plugin will depend on the status of the <code>Hidden From Listed Roles</code> checkbox.\n</li>\n<li class=\"mt-1\">\nIf the user exists in the listed <code>Users</code>, then the visibility of the plugin will depend on the status of the <code>Hidden From Listed Users</code> checkbox, bypassing the visibility status of listed <code>Roles</code>.\n</li>\n</ul>",
"options": "",
"read_only": 1
},
{
Expand Down
1 change: 0 additions & 1 deletion active_users/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Licence: Please refer to LICENSE file


from . import __version__ as app_version
from frappe import __version__ as frappe_version


Expand Down
12 changes: 6 additions & 6 deletions active_users/public/js/active_users.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ class ActiveUsers {
`);
$('header.navbar > .container > .navbar-collapse > ul.navbar-nav').prepend(this.$app.get(0));

this.$body = this.$app.find('.active-users-list-body');
this.$loading = this.$body.find('.active-users-list-loading').hide();
this.$footer = this.$app.find('.active-users-footer-text');
this.$reload = this.$app.find('.active-users-footer-reload');
this.$body = this.$app.find('.active-users-list-body').first();
this.$loading = this.$body.find('.active-users-list-loading').first().hide();
this.$footer = this.$app.find('.active-users-footer-text').first();
this.$reload = this.$app.find('.active-users-footer-reload').first();

this.setup_manual_sync();
}
Expand All @@ -159,10 +159,10 @@ class ActiveUsers {
return;
}
var me = this;
this.$reload.on('click', function(e) {
this.$reload.show().click(function(e) {
e.preventDefault();
if (!me._syncing) me.sync_reload();
}).show();
});
}
sync_reload() {
if (!this.is_online) return;
Expand Down
18 changes: 15 additions & 3 deletions active_users/setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ def after_install():

doc = settings(True)

if frappe.db.exists("User Type", "System User"):
user_types = None
if doc.user_types:
user_types = [v.user_type for v in doc.user_types]

if (
(
not user_types or
"System User" not in user_types
) and frappe.db.exists("User Type", "System User")
):
doc.append("user_types", {"user_type": "System User"})

roles = frappe.get_all(
Expand All @@ -32,11 +41,14 @@ def after_install():
pluck="name"
)
if roles:

user_roles = None
if doc.roles:
doc.roles.clear()
user_roles = [v.role for v in doc.roles]

for r in roles:
doc.append("roles", {"role": r})
if not user_roles or r not in user_roles:
doc.append("roles", {"role": r})

doc.save(ignore_permissions=True)

Expand Down
25 changes: 14 additions & 11 deletions active_users/setup/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Licence: Please refer to LICENSE file


import frappe
from frappe.utils import now
from frappe.utils.user import get_system_managers

Expand All @@ -15,22 +14,26 @@
def after_migrate():
managers = get_system_managers(only_name=True)
if managers:
if "Administrator" in managers:
sender = "Administrator"
else:
sender = managers[0]

doc = settings(True)
doc.update_notification_sender = sender

if (
not doc.update_notification_sender or
doc.update_notification_sender not in managers
):
admin = "Administrator"
doc.update_notification_sender = admin if admin in managers else managers.pop(0)

receivers = None
if doc.update_notification_receivers:
doc.update_notification_receivers.clear()
receivers = [v.user for v in doc.update_notification_receivers]

for manager in managers:
doc.append(
"update_notification_receivers",
{"user": manager}
)
if not receivers or manager not in receivers:
doc.append(
"update_notification_receivers",
{"user": manager}
)

doc.latest_version = __version__
doc.latest_check = now()
Expand Down
26 changes: 14 additions & 12 deletions active_users/utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
# Licence: Please refer to LICENSE file


import json
import re

import frappe
from frappe import _dict
from frappe import _, _dict
from frappe.utils import (
cint,
has_common,
Expand Down Expand Up @@ -81,14 +78,13 @@ def get_users():
cache = get_cache(_CACHE_, cache_key)

if cache and isinstance(cache, dict):
if get_datetime(cache.expiry) < now_datetime():
del_cache(_CACHE_, cache_key)
else:
if get_datetime(cache.expiry) >= now_datetime():
return {"users": cache.data}

del_cache(_CACHE_, cache_key)


tp = [0, -20, 0]

sess_expiry = frappe.get_system_settings("session_expiry")
if not sess_expiry or not isinstance(sess_expiry, str):
sess_expiry = frappe.get_system_settings("session_expiry_mobile")
Expand All @@ -108,11 +104,13 @@ def get_users():
if tpv:
tp[idx] = -abs(tpv)
idx += 1

else:
return {"error": 1, "message": "The system session expiry value is invalid."}
return {"error": 1, "message": _("The system session expiry value is invalid.")}

except Exception as exc:
log_error(exc)
return {"error": 1, "message": "Unable to parse the system session expiry value."}
return {"error": 1, "message": _("Unable to parse the system session expiry value.")}

now_dt = now()
start = add_to_date(now_dt, hours=tp[0], minutes=tp[1], seconds=tp[2], as_string=True, as_datetime=True)
Expand All @@ -135,10 +133,14 @@ def get_users():
if app.refresh_interval >= _CACHE_INTERVAL_:
set_cache(_CACHE_, cache_key, _dict({
"data": data,
"expiry": add_to_date(now_dt, minutes=_CACHE_INTERVAL_, as_string=True, as_datetime=True)
"expiry": add_to_date(
now_dt, minutes=_CACHE_INTERVAL_,
as_string=True, as_datetime=True
)
}))

return {"users": data}

except Exception as exc:
log_error(exc)
return {"error": 1, "message": "Unable to get the list of active users."}
return {"error": 1, "message": _("Unable to get the list of active users.")}
1 change: 1 addition & 0 deletions active_users/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
_CACHE_ = "Active Users"
_CACHE_INTERVAL_ = 10


def error(msg, throw=True):
frappe.log_error("Active Users", msg)
if throw:
Expand Down
9 changes: 7 additions & 2 deletions active_users/utils/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re

import frappe
from frappe import _
from frappe.utils import (
cint,
get_request_session,
Expand Down Expand Up @@ -127,8 +128,12 @@ def send_notification(version, sender, receivers, message):
"document_name": _SETTINGS_,
"from_user": sender,
"for_user": receiver,
"subject": "Active Users: A New Version Is Available",
"subject": "{0}: {1}".format(
_("Active Users"), _("A New Version Is Available")
),
"type": "Alert",
"email_content": f"<p><h2>Version {version}</h2></p>{message}",
"email_content": "<p><h2>{0} {1}</h2></p>{2}".format(
_("Version"), version, message
),
})
.insert(ignore_permissions=True, ignore_mandatory=True))

0 comments on commit 4907a80

Please sign in to comment.