sub display_job
{
my ($self, %arg) = @_ ;
- $self->can_do('r_view_job');
+ return if $self->cant_do('r_view_job');
$arg{order} = ' Job.JobId DESC ';
my $grp = $self->get_form(qw/qclient_group db_clients/);
unless ($grp->{qclient_group}) {
- return $self->error("Can't get group");
+ $self->display({ ID => $cur_id++,
+ client_group => "''",
+ %$grp,
+ }, "groups_edit.tpl");
+ return;
}
my $query = "
$self->can_do('r_group_mgnt');
my $arg = $self->get_form(qw/qclient_group jclients qnewgroup/);
+
+ if (!$arg->{qclient_group} and $arg->{qnewgroup}) {
+ my $query = "
+INSERT INTO client_group (client_group_name)
+VALUES ($arg->{qnewgroup})
+";
+ $self->dbh_do($query);
+ $arg->{qclient_group} = $arg->{qnewgroup};
+ }
+
unless ($arg->{qclient_group}) {
return $self->error("Can't get groups");
}
-
+
$self->{dbh}->begin_work();
my $query = "
$self->display_groups();
}
-
-sub groups_add
-{
- my ($self) = @_;
- $self->can_do('r_group_mgnt');
-
- my $arg = $self->get_form(qw/qclient_group/) ;
-
- unless ($arg->{qclient_group}) {
- $self->display({}, "groups_add.tpl");
- return 1;
- }
-
- my $query = "
-INSERT INTO client_group (client_group_name)
-VALUES ($arg->{qclient_group})
-";
-
- $self->dbh_do($query);
-
- $self->display_groups();
-}
-
sub display_groups
{
my ($self) = @_;
return 1;
}
-# TODO: avoir un mode qui coupe le programme avec une page d'erreur
-# we can also get all security and fill {security} hash
-sub can_do
+sub cant_do
{
my ($self, $action) = @_;
# is security enabled in configuration ?
if (not $self->{info}->{enable_security}) {
- return 1;
+ return 0
}
# admin is a special user that can do everything
if ($self->{loginname} eq 'admin') {
- return 1;
+ return 0;
}
# must be logged
if (!$self->{loginname}) {
- $self->error("Can't do $action, your are not logged. " .
- "Check security with your administrator");
- $self->display_end();
- exit (0);
+ $self->{error} = "Can't do $action, your are not logged. " .
+ "Check security with your administrator";
+ return 1;
}
$self->get_roles();
if (!$self->{security}->{$action}) {
- $self->error("$self->{loginname} sorry, but this action ($action) " .
- "is not permited. " .
- "Check security with your administrator");
+ $self->{error} =
+ "$self->{loginname} sorry, but this action ($action) " .
+ "is not permited. " .
+ "Check security with your administrator";
+ return 1;
+ }
+ return 0;
+}
+
+# make like an assert (program die)
+sub can_do
+{
+ my ($self, $action) = @_;
+ if ($self->cant_do($action)) {
+ $self->error($self->{error});
$self->display_end();
- exit (0);
+ exit 0;
}
return 1;
}
SET passwd=$arg->{qpasswd}, comment=$arg->{qcomment},
use_acl=$arg->{use_acl}
WHERE username = $u")
- and (! $self->dbh_is_mysql() )
- ) or
+# and (! $self->dbh_is_mysql() )
+ ) and
$self->dbh_do("
INSERT INTO bweb_user (username, passwd, use_acl, comment)
VALUES ($u, $arg->{qpasswd}, $arg->{use_acl}, $arg->{qcomment})");
sub display_client_stats
{
my ($self, %arg) = @_ ;
- $self->can_do('r_view_stats');
+ $self->can_do('r_view_stat');
my $client = $self->dbh_quote($arg{clientname});
# get security filter
sub display_running_job
{
my ($self) = @_;
- $self->can_do('r_view_running_job');
+ return if $self->cant_do('r_view_running_job');
my $arg = $self->get_form('client', 'jobid');
sub display_running_jobs
{
my ($self, $display_action) = @_;
- $self->can_do('r_view_running_job');
+ return if $self->cant_do('r_view_running_job');
# get security filter
my $filter = $self->get_client_filter();