<% # API my $api = gitprep_api; my $manager = app->manager; # Parameters my $op = param('op') || ''; my $user = param('user') || ''; my $project = param('project'); # Authentication unless ($api->logined($user)) { $self->redirect_to('/'); return; } # Rename project my $git = app->git; my $errors; if (lc $self->req->method eq 'post') { if ($op eq 'add') { my $params = $api->params; my $rule = [ collaborator => [ ['not_blank' => 'collaborator is empty.'], # Check user sub { my $collaborator = shift || ''; if ($collaborator eq $user) { return {result => 0, message => "User $collaborator is yourself"}; } else { my $row = app->dbi->model('user')->select(id => $collaborator)->one; return $row ? 1 : {result => 0, message => "User $collaborator don't exists"}; } } ] ]; my $vresult = app->vc->validate($params, $rule); if ($vresult->is_ok) { my $safe_params = $vresult->data; my $collaborator = $safe_params->{collaborator}; # Insert eval { app->dbi->model('collaboration')->insert( { user_id => $user, project_name => $project, collaborator_id => $collaborator } ); }; if (my $e = $@) { app->log->error(url_with . ": $e"); $errors = ['Internal Error']; } else { flash(message => "Collaborator $collaborator is added."); $self->redirect_to('current'); return; } } else { $errors = $vresult->messages; } } elsif ($op eq 'remove') { my $collaborator = param('collaborator'); # Delete eval { app->dbi->model('collaboration')->delete( where => { user_id => $user, project_name => $project, collaborator_id => $collaborator } ); }; if (my $e = $@) { app->log->error(url_with . ": $e"); $errors = ['Internal Error']; } else { flash(message => "Collaborator $collaborator is removed."); $self->redirect_to('current'); return; } } } my $collaborators = app->dbi->model('collaboration')->select( 'collaborator_id', where => {user_id => $user, project_name => $project}, append => 'order by collaborator_id' )->values; %> % layout 'common', title => 'Collaboration'; %= include '/include/header';
%= include '/include/errors', errors => $errors; %= include '/include/message', message => flash('message'); %= include '/include/project_header';
Manage Collaborators
% if (@$collaborators) { % for my $collaborator (@$collaborators) { % }
"><%= $collaborator %>
<%= hidden_field 'collaborator' => $collaborator %> (remove)
% }
<%= text_field 'collaborator', style => 'margin-bottom:0' %>
%= include '/include/footer';