From 9778bca32379f4a85f63c851bf044a6e30a685d3 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Sun, 30 Nov 2014 12:47:51 +0100 Subject: [PATCH] channel,tags: differentiate between user and admin (config) requests - use all argument, fixes #2517 --- src/api/api_channel.c | 25 ++++++++++++++++++------- src/channels.c | 6 ++++++ src/webui/static/app/chconf.js | 1 + src/webui/static/app/cteditor.js | 1 + src/webui/static/app/idnode.js | 4 ++++ 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/api/api_channel.c b/src/api/api_channel.c index 1dbf20d9..baeb21bd 100644 --- a/src/api/api_channel.c +++ b/src/api/api_channel.c @@ -34,6 +34,13 @@ api_channel_key_val(htsmsg_t *dst, const char *key, const char *val) htsmsg_add_msg(dst, NULL, e); } +static int +api_channel_is_all(access_t *perm, htsmsg_t *args) +{ + return htsmsg_get_bool_or_default(args, "all", 0) && + !access_verify2(perm, ACCESS_ADMIN); +} + // TODO: this will need converting to an idnode system static int api_channel_list @@ -41,11 +48,12 @@ api_channel_list { channel_t *ch; htsmsg_t *l; + int cfg = api_channel_is_all(perm, args); l = htsmsg_create_list(); pthread_mutex_lock(&global_lock); CHANNEL_FOREACH(ch) { - if (!channel_access(ch, perm, 0)) continue; + if (!cfg && !channel_access(ch, perm, 0)) continue; api_channel_key_val(l, idnode_uuid_as_str(&ch->ch_id), channel_get_name(ch)); } pthread_mutex_unlock(&global_lock); @@ -57,12 +65,13 @@ api_channel_list static void api_channel_grid - ( access_t *perm, idnode_set_t *ins, api_idnode_grid_conf_t *conf ) + ( access_t *perm, idnode_set_t *ins, api_idnode_grid_conf_t *conf, htsmsg_t *args ) { channel_t *ch; + int cfg = api_channel_is_all(perm, args); CHANNEL_FOREACH(ch) - if (channel_access(ch, perm, !access_verify2(perm, ACCESS_ADMIN))) + if (cfg || channel_access(ch, perm, 0)) idnode_set_add(ins, (idnode_t*)ch, &conf->filter); } @@ -91,10 +100,11 @@ api_channel_tag_list { channel_tag_t *ct; htsmsg_t *l; - + int cfg = api_channel_is_all(perm, args); + l = htsmsg_create_list(); TAILQ_FOREACH(ct, &channel_tags, ct_link) - if (channel_tag_access(ct, perm, 0)) + if (cfg || channel_tag_access(ct, perm, 0)) api_channel_key_val(l, idnode_uuid_as_str(&ct->ct_id), ct->ct_name); *resp = htsmsg_create_map(); htsmsg_add_msg(*resp, "entries", l); @@ -103,12 +113,13 @@ api_channel_tag_list static void api_channel_tag_grid - ( access_t *perm, idnode_set_t *ins, api_idnode_grid_conf_t *conf ) + ( access_t *perm, idnode_set_t *ins, api_idnode_grid_conf_t *conf, htsmsg_t *args ) { channel_tag_t *ct; + int cfg = api_channel_is_all(perm, args); TAILQ_FOREACH(ct, &channel_tags, ct_link) - if (channel_tag_access(ct, perm, !access_verify2(perm, ACCESS_ADMIN))) + if (cfg || channel_tag_access(ct, perm, 0)) idnode_set_add(ins, (idnode_t*)ct, &conf->filter); } diff --git a/src/channels.c b/src/channels.c index 2b9dd6bb..f6cdd9dd 100644 --- a/src/channels.c +++ b/src/channels.c @@ -193,9 +193,12 @@ htsmsg_t * channel_class_get_list(void *o) { htsmsg_t *m = htsmsg_create_map(); + htsmsg_t *p = htsmsg_create_map(); htsmsg_add_str(m, "type", "api"); htsmsg_add_str(m, "uri", "channel/list"); htsmsg_add_str(m, "event", "channel"); + htsmsg_add_u32(p, "all", 1); + htsmsg_add_msg(m, "params", p); return m; } @@ -1119,9 +1122,12 @@ htsmsg_t * channel_tag_class_get_list(void *o) { htsmsg_t *m = htsmsg_create_map(); + htsmsg_t *p = htsmsg_create_map(); htsmsg_add_str(m, "type", "api"); htsmsg_add_str(m, "uri", "channeltag/list"); htsmsg_add_str(m, "event", "channeltag"); + htsmsg_add_u32(p, "all", 1); + htsmsg_add_msg(m, "params", p); return m; } diff --git a/src/webui/static/app/chconf.js b/src/webui/static/app/chconf.js index 89570406..abc75752 100644 --- a/src/webui/static/app/chconf.js +++ b/src/webui/static/app/chconf.js @@ -216,6 +216,7 @@ tvheadend.channel_tab = function(panel, index) tvheadend.idnode_grid(panel, { url: 'api/channel', + all: 1, comet: 'channel', titleS: 'Channel', titleP: 'Channels', diff --git a/src/webui/static/app/cteditor.js b/src/webui/static/app/cteditor.js index 6634a7a9..c8690025 100644 --- a/src/webui/static/app/cteditor.js +++ b/src/webui/static/app/cteditor.js @@ -6,6 +6,7 @@ tvheadend.cteditor = function(panel, index) { tvheadend.idnode_grid(panel, { url: 'api/channeltag', + all: 1, titleS: 'Channel Tag', titleP: 'Channel Tags', iconCls: 'channelTags', diff --git a/src/webui/static/app/idnode.js b/src/webui/static/app/idnode.js index 38478674..d78604f7 100644 --- a/src/webui/static/app/idnode.js +++ b/src/webui/static/app/idnode.js @@ -1026,9 +1026,12 @@ tvheadend.idnode_grid = function(panel, conf) }); /* Store */ + var params = {}; + if (conf.all) params['all'] = 1; store = new Ext.data.JsonStore({ root: 'entries', url: conf.gridURL || (conf.url + '/grid'), + baseParams: params, autoLoad: true, id: 'uuid', totalProperty: 'total', @@ -1425,6 +1428,7 @@ tvheadend.idnode_grid = function(panel, conf) if (!conf.fields) { var p = {}; if (conf.list) p['list'] = conf.list; + if (conf.all) p['all'] = 1; tvheadend.Ajax({ url: conf.url + '/class', params: p,