1 #**************************************************************************
2 # Copyright (C) 2009 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
20 package NDIRC::Context;
77 sub assert_user_roles {
78 my ($self,@roles) = @_;
79 return 1 unless @roles;
81 my $need = Set::Object->new(@roles);
83 if ($self->roles->superset($need)){
90 sub check_user_roles {
91 my ($self,@roles) = @_;
94 eval { $self->assert_user_roles(@roles) };
100 $msg =~ s`<b>(.*?)</b>`${\(chr(2))}$1${\(chr(15))}`gi;
101 $msg =~ s`<c(\d+)>(.*?)</c>`${\(chr(3))}$1$2${\(chr(15))}`gi;
103 $self->server->command($self->reply_string . $msg);
109 my $query = $self->model->prepare(q{
110 SELECT role FROM group_roles
111 WHERE gid IN (SELECT gid FROM groupmembers JOIN users USING (uid)
112 WHERE hostmask ILIKE $1)
114 $query->execute($self->host);
117 while (my $group = $query->fetchrow_hashref){
118 push @roles,$group->{role};
120 return Set::Object->new(@roles);