Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: allow admin to edit owner/creator fields
  • Loading branch information
perexg committed Jun 1, 2015
1 parent 59732e0 commit ad7326e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/api/api_dvr.c
Expand Up @@ -33,8 +33,10 @@ api_dvr_config_grid
dvr_config_t *cfg;

LIST_FOREACH(cfg, &dvrconfigs, config_link)
if (!idnode_perm((idnode_t *)cfg, perm, NULL))
if (!idnode_perm((idnode_t *)cfg, perm, NULL)) {
idnode_set_add(ins, (idnode_t*)cfg, &conf->filter);
idnode_perm_unset((idnode_t *)cfg);
}
}

static int
Expand Down
26 changes: 22 additions & 4 deletions src/api/api_idnode.c
Expand Up @@ -122,6 +122,7 @@ api_idnode_grid
htsmsg_t *list, *e;
htsmsg_t *flist = api_idnode_flist_conf(args, "list");
api_idnode_grid_conf_t conf = { 0 };
idnode_t *in;
idnode_set_t ins = { 0 };
api_idnode_grid_callback_t cb = opaque;

Expand All @@ -141,7 +142,10 @@ api_idnode_grid
for (i = conf.start; i < ins.is_count && conf.limit != 0; i++) {
e = htsmsg_create_map();
htsmsg_add_str(e, "uuid", idnode_uuid_as_str(ins.is_array[i]));
idnode_read0(ins.is_array[i], e, flist, 0);
in = ins.is_array[i];
idnode_perm_set(in, perm);
idnode_read0(in, e, flist, 0);
idnode_perm_unset(in);
htsmsg_add_msg(list, NULL, e);
if (conf.limit > 0) conf.limit--;
}
Expand Down Expand Up @@ -200,9 +204,11 @@ api_idnode_load_by_class
e = idnode_serialize0(in, flist, 0);
htsmsg_destroy(flist);
}

if (e)
htsmsg_add_msg(l, NULL, e);

idnode_perm_unset(in);
}
free(is->is_array);
free(is);
Expand Down Expand Up @@ -267,6 +273,7 @@ api_idnode_load
htsmsg_add_msg(m, "meta", idclass_serialize0(in->in_class, flist, 0));
htsmsg_add_msg(l, NULL, m);
count++;
idnode_perm_unset(in);
}

if (count)
Expand All @@ -285,6 +292,7 @@ api_idnode_load
if (meta > 0)
htsmsg_add_msg(m, "meta", idclass_serialize0(in->in_class, flist, 0));
htsmsg_add_msg(l, NULL, m);
idnode_perm_unset(in);
}
}
}
Expand Down Expand Up @@ -331,6 +339,7 @@ api_idnode_save
goto exit;
}
idnode_update(in, msg);
idnode_perm_unset(in);
err = 0;

/* Multiple */
Expand All @@ -350,6 +359,7 @@ api_idnode_save
}
count++;
idnode_update(in, conf);
idnode_perm_unset(in);
}
if (count)
err = 0;
Expand Down Expand Up @@ -399,7 +409,10 @@ api_idnode_tree

/* Root node */
if (isroot && node) {
htsmsg_t *m = idnode_serialize(node);
htsmsg_t *m;
idnode_perm_set(node, perm);
m = idnode_serialize(node);
idnode_perm_unset(node);
htsmsg_add_u32(m, "leaf", idnode_is_leaf(node));
htsmsg_add_msg(*resp, NULL, m);

Expand All @@ -410,7 +423,11 @@ api_idnode_tree
int i;
idnode_set_sort_by_title(v);
for(i = 0; i < v->is_count; i++) {
htsmsg_t *m = idnode_serialize(v->is_array[i]);
idnode_t *in = v->is_array[i];
htsmsg_t *m;
idnode_perm_set(in, perm);
m = idnode_serialize(v->is_array[i]);
idnode_perm_unset(in);
htsmsg_add_u32(m, "leaf", idnode_is_leaf(v->is_array[i]));
htsmsg_add_msg(*resp, NULL, m);
}
Expand Down Expand Up @@ -498,6 +515,7 @@ api_idnode_handler
err = EPERM;
} else {
handler(perm, in);
idnode_perm_unset(in);
}
htsmsg_destroy(msg);
}
Expand Down
14 changes: 12 additions & 2 deletions src/dvr/dvr_autorec.c
Expand Up @@ -881,6 +881,16 @@ dvr_autorec_entry_class_dedup_list ( void *o )
return strtab2htsmsg(tab);
}

static uint32_t
dvr_autorec_entry_class_owner_opts(void *o)
{
dvr_autorec_entry_t *dae = (dvr_autorec_entry_t *)o;
if (dae && dae->dae_id.in_access &&
!access_verify2(dae->dae_id.in_access, ACCESS_ADMIN))
return 0;
return PO_RDONLY;
}

const idclass_t dvr_autorec_entry_class = {
.ic_class = "dvrautorec",
.ic_caption = "DVR Auto-Record Entry",
Expand Down Expand Up @@ -1065,14 +1075,14 @@ const idclass_t dvr_autorec_entry_class = {
.id = "owner",
.name = "Owner",
.off = offsetof(dvr_autorec_entry_t, dae_owner),
.opts = PO_RDONLY,
.get_opts = dvr_autorec_entry_class_owner_opts,
},
{
.type = PT_STR,
.id = "creator",
.name = "Creator",
.off = offsetof(dvr_autorec_entry_t, dae_creator),
.opts = PO_RDONLY,
.get_opts = dvr_autorec_entry_class_owner_opts,
},
{
.type = PT_STR,
Expand Down
18 changes: 14 additions & 4 deletions src/dvr/dvr_db.c
Expand Up @@ -1389,6 +1389,16 @@ dvr_entry_class_start_opts(void *o)
return 0;
}

static uint32_t
dvr_entry_class_owner_opts(void *o)
{
dvr_entry_t *de = (dvr_entry_t *)o;
if (de && de->de_id.in_access &&
!access_verify2(de->de_id.in_access, ACCESS_ADMIN))
return 0;
return PO_RDONLY;
}

static uint32_t
dvr_entry_class_start_extra_opts(void *o)
{
Expand Down Expand Up @@ -1977,7 +1987,7 @@ const idclass_t dvr_entry_class = {
.set = dvr_entry_class_start_extra_set,
.list = dvr_entry_class_extra_list,
.get_opts = dvr_entry_class_start_extra_opts,
.opts = PO_DURATION | PO_SORTKEY,
.opts = PO_SORTKEY,
},
{
.type = PT_TIME,
Expand All @@ -1999,7 +2009,7 @@ const idclass_t dvr_entry_class = {
.name = "Extra Stop Time",
.off = offsetof(dvr_entry_t, de_stop_extra),
.list = dvr_entry_class_extra_list,
.opts = PO_DURATION | PO_SORTKEY,
.opts = PO_SORTKEY,
},
{
.type = PT_TIME,
Expand Down Expand Up @@ -2127,14 +2137,14 @@ const idclass_t dvr_entry_class = {
.id = "owner",
.name = "Owner",
.off = offsetof(dvr_entry_t, de_owner),
.opts = PO_RDONLY,
.get_opts = dvr_entry_class_owner_opts,
},
{
.type = PT_STR,
.id = "creator",
.name = "Creator",
.off = offsetof(dvr_entry_t, de_creator),
.opts = PO_RDONLY,
.get_opts = dvr_entry_class_owner_opts,
},
{
.type = PT_STR,
Expand Down
14 changes: 12 additions & 2 deletions src/dvr/dvr_timerec.c
Expand Up @@ -532,6 +532,16 @@ dvr_timerec_entry_class_weekdays_rend(void *o)
return dvr_autorec_entry_class_weekdays_rend(dte->dte_weekdays);
}

static uint32_t
dvr_timerec_entry_class_owner_opts(void *o)
{
dvr_timerec_entry_t *dte = (dvr_timerec_entry_t *)o;
if (dte && dte->dte_id.in_access &&
!access_verify2(dte->dte_id.in_access, ACCESS_ADMIN))
return 0;
return PO_RDONLY;
}

const idclass_t dvr_timerec_entry_class = {
.ic_class = "dvrtimerec",
.ic_caption = "DVR Time-Record Entry",
Expand Down Expand Up @@ -635,14 +645,14 @@ const idclass_t dvr_timerec_entry_class = {
.id = "owner",
.name = "Owner",
.off = offsetof(dvr_timerec_entry_t, dte_creator),
.opts = PO_RDONLY,
.get_opts = dvr_timerec_entry_class_owner_opts,
},
{
.type = PT_STR,
.id = "creator",
.name = "Creator",
.off = offsetof(dvr_timerec_entry_t, dte_creator),
.opts = PO_RDONLY,
.get_opts = dvr_timerec_entry_class_owner_opts,
},
{
.type = PT_STR,
Expand Down
17 changes: 13 additions & 4 deletions src/idnode.c
Expand Up @@ -559,13 +559,22 @@ int
idnode_perm(idnode_t *self, struct access *a, htsmsg_t *msg_to_write)
{
const idclass_t *ic = self->in_class;
int r;

while (ic) {
if (ic->ic_perm)
return self->in_class->ic_perm(self, a, msg_to_write);
if (ic->ic_perm_def)
return access_verify2(a, self->in_class->ic_perm_def);
ic = ic->ic_super;
r = self->in_class->ic_perm(self, a, msg_to_write);
else if (ic->ic_perm_def)
r = access_verify2(a, self->in_class->ic_perm_def);
else {
ic = ic->ic_super;
continue;
}
if (!r) {
self->in_access = a;
return 0;
}
return r;
}
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions src/idnode.h
Expand Up @@ -87,6 +87,8 @@ struct idnode {
RB_ENTRY(idnode) in_domain_link; ///< Root class link (domain)
idnodes_rb_t *in_domain; ///< Domain nodes
const idclass_t *in_class; ///< Class definition
struct access *in_access; ///< Actual permissions

};

/*
Expand Down Expand Up @@ -178,6 +180,8 @@ int idnode_write0 (idnode_t *self, htsmsg_t *m, int optmask, int dosave);
#define idnode_update(in, m) idnode_write0(in, m, PO_RDONLY | PO_WRONCE, 1)

int idnode_perm(idnode_t *self, struct access *a, htsmsg_t *msg_to_write);
static inline void idnode_perm_set(idnode_t *self, struct access *a) { self->in_access = a; }
static inline void idnode_perm_unset(idnode_t *self) { self->in_access = NULL; }

const char *idnode_get_str (idnode_t *self, const char *key );
int idnode_get_u32 (idnode_t *self, const char *key, uint32_t *u32);
Expand Down
3 changes: 2 additions & 1 deletion src/webui/static/app/dvr.js
Expand Up @@ -156,6 +156,7 @@ tvheadend.dvr_upcoming = function(panel, index) {
var actions = tvheadend.dvrRowActions();
var list = 'disp_title,start,start_extra,stop,stop_extra,' +
'channel,config_name,comment';
var elist = tvheadend.accessUpdate.admin ? list + ',owner,creator' : list;

var abortButton = {
name: 'abort',
Expand Down Expand Up @@ -217,7 +218,7 @@ tvheadend.dvr_upcoming = function(panel, index) {
},
edit: {
params: {
list: list
list: elist
}
},
del: true,
Expand Down

0 comments on commit ad7326e

Please sign in to comment.