From fb734d8d744088733e873b05e768c84f993e5b35 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Wed, 2 Dec 2015 18:18:14 +0100 Subject: [PATCH] WEBUI: Add persistent view level settings (global + per ACL) --- src/access.c | 27 +++++++++++++++++++++++++++ src/access.h | 2 ++ src/config.c | 8 ++++++++ src/config.h | 1 + src/webui/comet.c | 5 ++++- src/webui/static/app/acleditor.js | 4 ++-- src/webui/static/app/idnode.js | 8 ++++---- src/webui/static/app/tvheadend.js | 4 ++++ 8 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/access.c b/src/access.c index f61ccb077..061868f3a 100644 --- a/src/access.c +++ b/src/access.c @@ -489,6 +489,7 @@ static access_t *access_alloc(void) { access_t *a = calloc(1, sizeof(access_t)); a->aa_uilevel = -1; + a->aa_uilevel_nochange = -1; return a; } @@ -499,6 +500,7 @@ static access_t *access_full(access_t *a) { a->aa_rights = ACCESS_FULL; a->aa_uilevel = UILEVEL_EXPERT; + a->aa_uilevel_nochange = config.uilevel_nochange; return a; } @@ -529,6 +531,9 @@ access_update(access_t *a, access_entry_t *ae) if(ae->ae_uilevel > a->aa_uilevel) a->aa_uilevel = ae->ae_uilevel; + if(ae->ae_uilevel_nochange > a->aa_uilevel_nochange) + a->aa_uilevel_nochange = ae->ae_uilevel_nochange; + if(ae->ae_chmin || ae->ae_chmax) { uint64_t *p = realloc(a->aa_chrange, (a->aa_chrange_count + 2) * sizeof(uint64_t)); if (p) { @@ -610,6 +615,8 @@ access_set_lang_ui(access_t *a) } if (a->aa_uilevel < 0) a->aa_uilevel = config.uilevel; + if (a->aa_uilevel_nochange < 0) + a->aa_uilevel_nochange = config.uilevel_nochange; } /** @@ -1042,6 +1049,7 @@ access_entry_create(const char *uuid, htsmsg_t *conf) TAILQ_INIT(&ae->ae_ipmasks); ae->ae_uilevel = UILEVEL_DEFAULT; + ae->ae_uilevel_nochange = -1; if (conf) { /* defaults */ @@ -1372,6 +1380,17 @@ uilevel_get_list ( void *o, const char *lang ) return strtab2htsmsg(tab, 1, lang); } +static htsmsg_t * +uilevel_nochange_get_list ( void *o, const char *lang ) +{ + static const struct strtab tab[] = { + { N_("Default"), -1 }, + { N_("No"), 0 }, + { N_("Yes"), 1 }, + }; + return strtab2htsmsg(tab, 1, lang); +} + const idclass_t access_entry_class = { .ic_class = "access", .ic_caption = N_("Access"), @@ -1418,6 +1437,14 @@ const idclass_t access_entry_class = { .list = uilevel_get_list, .opts = PO_EXPERT }, + { + .type = PT_INT, + .id = "uilevel_nochange", + .name = N_("Persistent user interface level"), + .off = offsetof(access_entry_t, ae_uilevel_nochange), + .list = uilevel_nochange_get_list, + .opts = PO_EXPERT + }, { .type = PT_STR, .id = "lang", diff --git a/src/access.h b/src/access.h index 67ed47130..bbc300888 100644 --- a/src/access.h +++ b/src/access.h @@ -99,6 +99,7 @@ typedef struct access_entry { int ae_index; int ae_enabled; int ae_uilevel; + int ae_uilevel_nochange; int ae_streaming; int ae_adv_streaming; @@ -151,6 +152,7 @@ typedef struct access { uint32_t aa_conn_streaming; uint32_t aa_conn_dvr; int aa_uilevel; + int aa_uilevel_nochange; } access_t; TAILQ_HEAD(access_ticket_queue, access_ticket); diff --git a/src/config.c b/src/config.c index fee044033..824a736c3 100644 --- a/src/config.c +++ b/src/config.c @@ -1974,6 +1974,14 @@ const idclass_t config_class = { .list = config_class_uilevel, .group = 1 }, + { + .type = PT_BOOL, + .id = "uilevel_nochange", + .name = N_("Persistent user interface level"), + .off = offsetof(config_t, uilevel_nochange), + .opts = PO_ADVANCED, + .group = 1 + }, { .type = PT_U32, .id = "cookie_expires", diff --git a/src/config.h b/src/config.h index c4f4126e0..57798bfb6 100644 --- a/src/config.h +++ b/src/config.h @@ -31,6 +31,7 @@ typedef struct config { idnode_t idnode; uint32_t version; int uilevel; + int uilevel_nochange; char *full_version; char *server_name; char *language; diff --git a/src/webui/comet.c b/src/webui/comet.c index 42ec2c226..f2dfc5cc1 100644 --- a/src/webui/comet.c +++ b/src/webui/comet.c @@ -160,8 +160,11 @@ comet_access_update(http_connection_t *hc, comet_mailbox_t *cmb) case UILEVEL_EXPERT: s = "expert"; break; default: s = NULL; break; } - if (s) + if (s) { htsmsg_add_str(m, "uilevel", s); + if (config.uilevel_nochange) + htsmsg_add_u32(m, "uilevel_nochange", config.uilevel_nochange); + } if (!access_noacl) htsmsg_add_str(m, "username", username); if (hc->hc_peer_ipstr) diff --git a/src/webui/static/app/acleditor.js b/src/webui/static/app/acleditor.js index 6735667c1..0afc2c8c6 100644 --- a/src/webui/static/app/acleditor.js +++ b/src/webui/static/app/acleditor.js @@ -5,7 +5,7 @@ tvheadend.acleditor = function(panel, index) { var list = 'enabled,username,password,prefix,' + - 'lang,webui,uilevel,admin,' + + 'lang,webui,uilevel,uilevel_nochange,admin,' + 'streaming,adv_streaming,htsp_streaming,' + 'profile,conn_limit_type,conn_limit,' + 'dvr,htsp_dvr,all_dvr,all_rw_dvr,' + @@ -13,7 +13,7 @@ tvheadend.acleditor = function(panel, index) 'channel_tag_exclude,channel_tag,comment'; var list2 = 'enabled,username,password,prefix,' + - 'lang,webui,langui,uilevel,admin,' + + 'lang,webui,langui,uilevel,uilevel_nochange,admin,' + 'streaming,adv_streaming,htsp_streaming,' + 'profile,conn_limit_type,conn_limit,' + 'dvr,htsp_dvr,all_dvr,all_rw_dvr,' + diff --git a/src/webui/static/app/idnode.js b/src/webui/static/app/idnode.js index 51a24a507..84d1655bf 100644 --- a/src/webui/static/app/idnode.js +++ b/src/webui/static/app/idnode.js @@ -1079,7 +1079,7 @@ tvheadend.idnode_editor = function(_uilevel, item, conf) } var uilevelBtn = null; - if (!conf.uilevel || conf.uilevel !== 'expert') { + if (!tvheadend.uilevel_nochange && (!conf.uilevel || conf.uilevel !== 'expert')) { uilevelBtn = tvheadend.idnode_uilevel_menu(uilevel, function(l) { uilevel = l; var values = panel.getForm().getFieldValues(); @@ -1817,7 +1817,7 @@ tvheadend.idnode_grid = function(panel, conf) } } - if (!conf.uilevel || conf.uilevel !== 'expert') { + if (!tvheadend.uilevel_nochange && (!conf.uilevel || conf.uilevel !== 'expert')) { abuttons.uilevel = tvheadend.idnode_uilevel_menu(uilevel, function (l) { uilevel = l; for (var i = 0; i < ifields.length; i++) { @@ -2185,7 +2185,7 @@ tvheadend.idnode_form_grid = function(panel, conf) } } - if (!conf.uilevel || conf.uilevel !== 'expert') { + if (!tvheadend.uilevel_nochange && (!conf.uilevel || conf.uilevel !== 'expert')) { abuttons.uilevel = tvheadend.idnode_uilevel_menu(uilevel, function (l) { uilevel = l; var values = null; @@ -2626,7 +2626,7 @@ tvheadend.idnode_simple = function(panel, conf) } } - if (!conf.uilevel || conf.uilevel !== 'expert') { + if (!tvheadend.uilevel_nochange && (!conf.uilevel || conf.uilevel !== 'expert')) { abuttons.uilevel = tvheadend.idnode_uilevel_menu(uilevel, uilevel_change); buttons.push('->'); buttons.push(abuttons.uilevel); diff --git a/src/webui/static/app/tvheadend.js b/src/webui/static/app/tvheadend.js index 47ea31fe4..1b9d8551c 100644 --- a/src/webui/static/app/tvheadend.js +++ b/src/webui/static/app/tvheadend.js @@ -4,6 +4,7 @@ tvheadend.capabilities = null; tvheadend.admin = false; tvheadend.dialog = null; tvheadend.uilevel = 'expert'; +tvheadend.uilevel_nochange = false; tvheadend.uilevel_cb = []; tvheadend.cookieProvider = new Ext.state.CookieProvider({ @@ -429,6 +430,9 @@ function accessUpdate(o) { tvheadend.admin = o.admin == true; + if (o.uilevel_nochange) + tvheadend.uilevel_nochange = true; + if ('info_area' in o) tvheadend.rootTabPanel.setInfoArea(o.info_area); if ('username' in o) -- 2.47.3