summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-26 22:14:02 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-26 22:14:02 (GMT)
commit6ac2fd07b57a25aa9ae2f8128f6e3e65cb8001ed (patch)
treeaab469fd94fd231456f1b25995e49d6309e65b17
parent343ac9e3baec46fef765d7193a92555fea7e288c (diff)
no more specialusers config (use DB instead)
-rwxr-xr-xlib/RHRD/rddb.pm49
-rwxr-xr-xtest/music-grids47
2 files changed, 88 insertions, 8 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index 10148f8..8f519c6 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -60,9 +60,6 @@ sub init
$ctx{'config'}{'specialgroups'}{'alljingles'} = $cfg->val('specialgroups', 'alljingles', 'ALL_JINGLE');
@{$ctx{'config'}{'specialusers'}{'no-update-token'}} = split(' ', $cfg->val('specialusers', 'no-update-token', ''));
- @{$ctx{'config'}{'specialusers'}{'admins'}} = split(' ', $cfg->val('specialusers', 'admins', 'admin'));
- @{$ctx{'config'}{'specialusers'}{'allshows'}} = split(' ', $cfg->val('specialusers', 'allshows', ''));
- @{$ctx{'config'}{'specialusers'}{'allpools'}} = split(' ', $cfg->val('specialusers', 'allpools', ''));
$ctx{'config'}{'dropboxes'}{'dropbox-pseudo-station'} = $cfg->val('dropboxes', 'dropbox-pseudo-station', 'import-dropbox');
$ctx{'config'}{'dropboxes'}{'norm-level'} = $cfg->val('dropboxes', 'norm-level', -1200);
@@ -1252,7 +1249,11 @@ sub create_show_group
or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
$sth->finish();
- for my $user (@{$ctx->{'config'}{'specialusers'}{'allshows'}}) {
+ my @users = get_group_members($ctx, $ctx->{'config'}{'specialgroups'}{'allshows'});
+ if(!defined $users[0] && defined $users[1]) {
+ return (undef, $users[1], $users[2]);
+ }
+ for my $user (@users) {
($cnt, $status, $errorstring) = RHRD::rddb::add_group_member($ctx, $groupname, $user);
return (undef, $status, $errorstring) unless(defined $cnt);
}
@@ -1759,14 +1760,46 @@ sub is_musicpools_user
return 0 if $username eq '';
- for my $groupuser (@{$ctx->{'config'}{'specialusers'}{'allpools'}}) {
- if ($username eq $groupuser) {
- return 1;
- }
+ my $sql = qq{select MODIFY_TEMPLATE_PRIV from USERS where LOGIN_NAME = ?;};
+ my $sth = $ctx->{'dbh'}->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+ $sth->execute($username)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my ($priv) = $sth->fetchrow_array;
+ $sth->finish();
+
+ unless(defined $priv) {
+ return (undef, 'ERROR', "user '" . $username . "' not known by rivendell")
+ }
+
+ if($priv eq "Y") {
+ return 1;
}
return 0;
}
+sub set_musicpools_user
+{
+ my ($ctx, $username, $value) = @_;
+
+ if(defined($value) && $value) {
+ $value = "Y";
+ } else {
+ $value = "N";
+ }
+
+ my $sql = qq{update USERS set MODIFY_TEMPLATE_PRIV = ? where LOGIN_NAME = ?;};
+ my $rows = $ctx->{'dbh'}->do($sql, undef, $value, $username)
+ or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+ unless($rows == 1) {
+ return (undef, 'ERROR', "user '" . $username . "' not known by rivendell")
+ }
+ return (1, 'OK', 'success');
+}
+
sub get_musicpools_clocks
{
my ($ctx) = @_;
diff --git a/test/music-grids b/test/music-grids
new file mode 100755
index 0000000..35bb702
--- /dev/null
+++ b/test/music-grids
@@ -0,0 +1,47 @@
+#!/usr/bin/perl -w
+#
+# rhrdlibs
+#
+# Copyright (C) 2015-2016 Christian Pointner <equinox@helsinki.at>
+#
+# This file is part of rhrdlibs.
+#
+# rhrdlibs is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# any later version.
+#
+# rhrdlibs is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with rhrdlibs. If not, see <http://www.gnu.org/licenses/>.
+#
+
+use strict;
+use POSIX;
+use lib "../lib/";
+use RHRD::rddb;
+
+my ($ctx, $status, $errorstring) = RHRD::rddb::init();
+if(defined $ctx) {
+ my $username = "";
+ $username = $ARGV[0] if(defined($ARGV[0]));
+ (my $authorized, $status, $errorstring) = RHRD::rddb::is_musicpools_user($ctx, $username);
+ if(!defined $authorized) {
+ print STDERR "$status: $errorstring\n";
+ RHRD::rddb::destroy($ctx);
+ exit 1;
+ }
+ if($authorized) {
+ print "'$username' is allowed to edit music grids\n";
+ } else {
+ print "'$username' is *not* allowed to edit music grids\n";
+ }
+ RHRD::rddb::destroy($ctx);
+} else {
+ print STDERR "$errorstring\n";
+ exit 1;
+}