Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
fix: fix invite user endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Lane Seppala authored and lseppala committed Mar 7, 2018
1 parent d091534 commit 5f488e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 40 deletions.
16 changes: 0 additions & 16 deletions Conch/cpanfile.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3810,22 +3810,6 @@ DISTRIBUTIONS
requirements:
ExtUtils::MakeMaker 0
Test::More 0
Time-Moment-0.42
pathname: C/CH/CHANSEN/Time-Moment-0.42.tar.gz
provides:
Time::Moment 0.42
Time::Moment::Adjusters 0.42
requirements:
Carp 0
ExtUtils::MakeMaker 6.59
ExtUtils::ParseXS 3.18
Test::Fatal 0.006
Test::More 0.88
Test::Number::Delta 1.06
Test::Requires 0
Time::HiRes 0
XSLoader 0.02
perl 5.008001
Time-Warp-0.52
pathname: S/SZ/SZABGAB/Time-Warp-0.52.tar.gz
provides:
Expand Down
40 changes: 16 additions & 24 deletions Conch/lib/Conch/Controller/WorkspaceUser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use Data::Printer;
use Conch::Models;
use Conch::Pg;


=head2 list
Get a list of users for the current stashed C<current_workspace>
Expand All @@ -25,12 +24,10 @@ Get a list of users for the current stashed C<current_workspace>

sub list ($c) {
my $users = Conch::Model::WorkspaceUser->new->workspace_users(
$c->stash('current_workspace')->id
);
$c->stash('current_workspace')->id );
$c->status( 200, [ map { $_->as_v1_json } @$users ] );
}


=head2 invite
Invite a user to the current stashed C<current_workspace>
Expand All @@ -42,21 +39,24 @@ sub invite ($c) {
return $c->status( 400, { error => '"user" and "role " fields required ' } )
unless ( $body->{user} and $body->{role} );

return $c->status(403) if $c->stash('current_workspace')->role eq 'Read-only';
return $c->status(403) if $c->stash('current_workspace')->role eq 'Integrator';
return $c->status(403)
if $c->stash('current_workspace')->role eq 'Read-only';
return $c->status(403)
if $c->stash('current_workspace')->role eq 'Integrator';

my $ws = $c->stash('current_workspace');
my $maybe_role = $c->role->lookup_by_name( $body->{role} );
my $ws = $c->stash('current_workspace');
my $maybe_role =
Conch::Model::WorkspaceRole->new->lookup_by_name( $body->{role} );

unless ( $maybe_role ) {
my $role_names = join( ', ', map { $_->name } @{ $c->role->list() } );
unless ($maybe_role) {
my $role_names =
join( ', ',
map { $_->name } @{ Conch::Model::WorkspaceRole->new->list } );
return $c->status( 400,
{ error => '"role" must be one of: ' . $role_names } );
}

my $user = Conch::Model::User->lookup_by_email(
$body->{user}
);
my $user = Conch::Model::User->lookup_by_email( $body->{user} );

if ($user) {
$c->mail->send_existing_user_invite(
Expand All @@ -68,25 +68,18 @@ sub invite ($c) {
}
else {
my $password = $c->random_string( length => 10 );
$user = Conch::Model::User->create(
$body->{user},
$password
);
$user = Conch::Model::User->create( $body->{user}, $password );
$c->mail->send_new_user_invite(
{ email => $user->email, password => $password } );
}

Conch::Model::Workspace->new->add_user_to_workspace(
$user->id,
$ws->id,
$maybe_role->id
);
Conch::Model::Workspace->new->add_user_to_workspace( $user->id, $ws->id,
$maybe_role->id );
$c->status(201);
}

1;


__DATA__
=pod
Expand All @@ -100,4 +93,3 @@ v.2.0. If a copy of the MPL was not distributed with this file, You can obtain
one at http://mozilla.org/MPL/2.0/.
=cut

0 comments on commit 5f488e1

Please sign in to comment.