Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
channel,tags: differentiate between user and admin (config) requests …
…- use all argument, fixes #2517
  • Loading branch information
perexg committed Nov 30, 2014
1 parent 452ca85 commit 9778bca
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/api/api_channel.c
Expand Up @@ -34,18 +34,26 @@ 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
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions src/channels.c
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/webui/static/app/chconf.js
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/webui/static/app/cteditor.js
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions src/webui/static/app/idnode.js
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9778bca

Please sign in to comment.