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;
26 use namespace::autoclean;
66 sub assert_user_roles {
67 my ($self,@roles) = @_;
68 return 1 unless @roles;
70 my $need = Set::Object->new(@roles);
72 if ($self->roles->superset($need)){
79 sub check_user_roles {
80 my ($self,@roles) = @_;
83 eval { $self->assert_user_roles(@roles) };
93 my ($c,$planet, $message) = @_;
94 my $log = $c->model->prepare_cached(q{
95 INSERT INTO forum_posts (ftid,uid,message) VALUES(
96 (SELECT ftid FROM planets WHERE pid = $3),$1,$2)
98 $log->execute($c->uid,$message,$planet);
102 my ($c,$call, $message) = @_;
103 my $log = $c->model->prepare(q{
104 INSERT INTO forum_posts (ftid,uid,message) VALUES(
105 (SELECT ftid FROM calls WHERE call = $3),$1,$2)
107 $log->execute($c->uid,$message,$call);
113 my $query = $self->model->prepare(q{
114 SELECT role FROM group_roles
115 WHERE gid IN (SELECT gid FROM groupmembers JOIN users USING (uid)
118 $query->execute($self->uid);
121 while (my $group = $query->fetchrow_hashref){
122 push @roles,$group->{role};
124 return Set::Object->new(@roles);
139 __PACKAGE__->meta->make_immutable;