summaryrefslogtreecommitdiff
path: root/lib/RHRD
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-09-28 16:40:41 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2015-09-28 16:40:41 (GMT)
commitbcd58fdfc6d8496d5fa250aa8d6e0d0d3a89d49d (patch)
tree8d3349a97488e9256ab105dc65e581d5b185e369 /lib/RHRD
parent222541ee6348f21a0b8107bebb3701422614ba88 (diff)
add group membership functions
Diffstat (limited to 'lib/RHRD')
-rwxr-xr-xlib/RHRD/rddb.pm72
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index a337557..f8832d1 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -534,6 +534,78 @@ sub set_group_reports
return ($cnt, 'OK', "Success");
}
+sub get_group_members
+{
+ my ($dbh, $groupname) = @_;
+
+ my $sql = qq{select USER_NAME from USER_PERMS where GROUP_NAME = ?;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $sth->execute($groupname)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my @users;
+ while(my ($user) = $sth->fetchrow_array()) {
+ push @users, $user;
+ }
+ $sth->finish();
+
+ return @users;
+}
+
+sub is_group_member
+{
+ my ($dbh, $groupname, $username) = @_;
+
+ my $sql = qq{select count(*) from USER_PERMS where GROUP_NAME = ? and USER_NAME = ?;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $sth->execute($groupname, $username)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my ($cnt) = $sth->fetchrow_array();
+ $sth->finish();
+
+ return ($cnt, 'OK', "success");
+}
+
+sub add_group_member
+{
+ my ($dbh, $groupname, $username) = @_;
+
+ my ($cnt, $result, $errostring) = is_group_member($dbh, $groupname, $username);
+ if($cnt > 0) {
+ return (undef, 'ERROR', "already a member");
+ }
+
+ my $sql = qq{insert into USER_PERMS (GROUP_NAME, USER_NAME) values (?, ?);};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $cnt = $sth->execute($groupname, $username)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ $sth->finish();
+ return ($cnt, 'OK', "success");
+}
+
+sub remove_group_member
+{
+ my ($dbh, $groupname, $username) = @_;
+
+ my $sql = qq{delete from USER_PERMS where GROUP_NAME = ? and USER_NAME = ?;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ my $cnt = $sth->execute($groupname, $username)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ $sth->finish();
+ return ($cnt, 'OK', "success");
+}
+
########################### SHOW handling ###########################
sub get_showtitle_and_log