<% # API my $api = gitprep_api; my $manager = app->manager; # Parameters my $op = param('op') || ''; my $user_id = param('user') || ''; my $project_id = param('project'); # Authentication unless ($api->logined($user_id)) { $self->redirect_to('/'); return; } my $project_row_id = app->dbi->model('project')->select( 'project.row_id', where => {'user.id' => $user_id, 'project.id' => $project_id} )->value; # Rename project my $git = app->git; my $errors; if (lc $self->req->method eq 'post') { if ($op eq 'add') { my $collaborator_id = param('collaborator'); # Validator my $vc = app->vc; # Validation result my $validation = $vc->validation; # collaborator check if (!length $collaborator_id) { $validation->add_failed(collaborator => "collaborator is empty"); } elsif ($collaborator_id eq $user_id) { $validation->add_failed(collaborator => "User $collaborator_id is yourself"); } else { my $row = app->dbi->model('user')->select( where => {id => $collaborator_id} )->one; if (!$row) { $validation->add_failed(collaborator => "User $collaborator_id don't exists"); } else { my $row = app->dbi->model('collaboration')->select( where => {project => $project_row_id, 'user.id' => $collaborator_id} )->one; if ($row) { $validation->add_failed(collaborator => "Collaborator $collaborator_id already exists"); } } } if ($validation->is_valid) { my $collaborator_row_id = $api->get_user_row_id($collaborator_id); # Insert eval { app->dbi->model('collaboration')->insert( { project => $project_row_id, user => $collaborator_row_id } ); }; if (my $e = $@) { app->log->error(url_with . ": $e"); $errors = ['Internal Error']; } else { flash(message => "Collaborator $collaborator_id is added."); $self->redirect_to('current'); return; } } else { $errors = $validation->messages; } } elsif ($op eq 'remove') { my $collaborator_id = param('collaborator'); my $collaborator_row_id = $api->get_user_row_id($collaborator_id); # Delete eval { app->dbi->model('collaboration')->delete( where => { project => $project_row_id, user => $collaborator_row_id } ); }; if (my $e = $@) { app->log->error(url_with . ": $e"); $errors = ['Internal Error']; } else { flash(message => "Collaborator $collaborator_id is removed."); $self->redirect_to('current'); return; } } } my $collaborators = app->dbi->model('collaboration')->select( {user => ['id']}, where => {project => $project_row_id}, append => 'order by collaboration.user' )->all; %> % layout 'common', title => 'Collaboration'; %= include '/include/header';
%= include '/include/errors', errors => $errors; %= include '/include/message', message => flash('message');
Manage Collaborators
% if (@$collaborators) { % for my $collaborator (@$collaborators) { % }
{'user.id'}") %>"><%= $collaborator->{'user.id'} %>
<%= hidden_field 'collaborator' => $collaborator->{'user.id'} %> (remove)
% }
<%= text_field 'collaborator' %>
%= include '/include/footer';