diff --git a/ddl/templates/versions/10/up.sql b/ddl/templates/versions/10/up.sql index bb93c534c7..0ce15ffffe 100644 --- a/ddl/templates/versions/10/up.sql +++ b/ddl/templates/versions/10/up.sql @@ -4,7 +4,7 @@ CREATE TABLE cell_lines ( ); GRANT SELECT ON cell_lines TO "[% ro_role %]"; GRANT SELECT, INSERT, UPDATE, DELETE ON cell_lines TO "[% rw_role %]"; - +GRANT USAGE ON cell_lines_id_seq TO "[% rw_role %]"; INSERT INTO cell_lines (name) SELECT DISTINCT cell_line @@ -28,4 +28,4 @@ ALTER TABLE process_cell_line DROP COLUMN cell_line; ALTER TABLE audit.process_cell_line -DROP COLUMN cell_line; \ No newline at end of file +DROP COLUMN cell_line; diff --git a/lib/LIMS2/Model/FormValidator/Constraint.pm b/lib/LIMS2/Model/FormValidator/Constraint.pm index 60bbe51c48..eaabc953f2 100644 --- a/lib/LIMS2/Model/FormValidator/Constraint.pm +++ b/lib/LIMS2/Model/FormValidator/Constraint.pm @@ -203,11 +203,6 @@ sub existing_design_oligo_type { return in_resultset( $model, 'DesignOligoType', 'id' ); } -#sub existing_pipeline { -# my ( $class, $model ) = @_; -# return in_resultset( $model, 'Pipeline', 'name' ); -#} - sub existing_plate_type { my ( $class, $model ) = @_; return in_resultset( $model, 'PlateType', 'id' ); @@ -398,6 +393,11 @@ sub pass_or_fail { return regexp_matches(qr/^(pass|fail)$/i); } +# at least 6 non whitespace characters long +sub password_string { + return regexp_matches(qr/^\S{6,}$/); +} + 1; __END__ diff --git a/lib/LIMS2/Model/Plugin/BAC.pm b/lib/LIMS2/Model/Plugin/BAC.pm index d00d470d62..16c5a28f44 100644 --- a/lib/LIMS2/Model/Plugin/BAC.pm +++ b/lib/LIMS2/Model/Plugin/BAC.pm @@ -27,7 +27,7 @@ sub _chr_id_for { return $chr->id; } -sub pspec_list_bac_libraies { +sub pspec_list_bac_libraries { return { species => { validate => 'existing_species', rename => 'species_id' } } diff --git a/lib/LIMS2/Model/Plugin/Design.pm b/lib/LIMS2/Model/Plugin/Design.pm index e63544a866..878cbc8177 100644 --- a/lib/LIMS2/Model/Plugin/Design.pm +++ b/lib/LIMS2/Model/Plugin/Design.pm @@ -169,18 +169,21 @@ sub delete_design { # Check that design is not assigned to a gene if ( $design->genes_rs->count > 0 ) { - $self->throw( InvalidState => 'Design ' . $design->design_id . ' has been assigned to one or more genes' ); + $self->throw( InvalidState => 'Design ' . $design->id . ' has been assigned to one or more genes' ); } # # Check that design is not allocated to a process and, if it is, refuse to delete if ( $design->process_designs_rs->count > 0 ) { - $self->throw( InvalidState => 'Design ' . $design->design_id . ' has been used in one or more processes' ); + $self->throw( InvalidState => 'Design ' . $design->id . ' has been used in one or more processes' ); } if ( $validated_params->{cascade} ) { $design->comments_rs->delete; - $design->oligos_rs->delete; $design->genotyping_primers_rs->delete; + for my $oligo ( $design->oligos_rs->all ) { + $oligo->loci_rs->delete; + $oligo->delete; + } } $design->delete; @@ -280,7 +283,7 @@ sub _get_gene_chr_start_end_strand { $self->throw( NotFound => { message => 'Found no matching EnsEMBL genes', - entity => 'EnsEMBL Gene', + entity_class => 'EnsEMBL Gene', search_params => { external_id => $gene_id } } ); diff --git a/lib/LIMS2/Model/Plugin/Process.pm b/lib/LIMS2/Model/Plugin/Process.pm index 19174d1a6d..07cebd6a87 100644 --- a/lib/LIMS2/Model/Plugin/Process.pm +++ b/lib/LIMS2/Model/Plugin/Process.pm @@ -60,7 +60,7 @@ sub delete_process { $process->delete; - return; + return 1; } sub list_process_types { diff --git a/lib/LIMS2/Model/Plugin/User.pm b/lib/LIMS2/Model/Plugin/User.pm index dc7c5fe558..bdb6f153dd 100644 --- a/lib/LIMS2/Model/Plugin/User.pm +++ b/lib/LIMS2/Model/Plugin/User.pm @@ -244,6 +244,32 @@ sub set_user_preferences { return $prefs; } +sub pspec_change_user_password { + return { + id => { validate => 'integer' }, + new_password => { validate => 'password_string' }, + new_password_confirm => { validate => 'password_string' }, + }; +} + +sub change_user_password { + my ( $self, $params ) = @_; + + my $validated_params = $self->check_params( $params, $self->pspec_change_user_password ); + + $self->throw( Validation => 'new password and password confirm values do not match' ) + unless $validated_params->{new_password} eq $validated_params->{new_password_confirm}; + + my $user = $self->retrieve( User => { id => $validated_params->{id} } ); + + my $csh = Crypt::SaltedHash->new( algorithm => "SHA-1" ); + $csh->add( $validated_params->{new_password} ); + + $user->update( { password => $csh->generate } ); + + return $user; +} + 1; __END__ diff --git a/lib/LIMS2/WebApp/Controller/User/UserPreferences.pm b/lib/LIMS2/WebApp/Controller/User/UserPreferences.pm new file mode 100644 index 0000000000..60ceefc497 --- /dev/null +++ b/lib/LIMS2/WebApp/Controller/User/UserPreferences.pm @@ -0,0 +1,88 @@ +package LIMS2::WebApp::Controller::User::UserPreferences; +use Moose; +use namespace::autoclean; +use Try::Tiny; + +BEGIN {extends 'Catalyst::Controller'; } + +=head1 NAME + +LIMS2::WebApp::Controller::User::UserPreferences - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + +# Need to have edit writes to make any changes in db, including password +# so users with only the read role can not change their password at the moment +# TODO: see if there is a way to get around this if its worth doing +sub begin :Private { + my ( $self, $c ) = @_; + + $c->assert_user_roles( 'edit' ); + return; +} + +sub change_password :Path( '/user/change_password' ) :Args(0) { + my ( $self, $c ) = @_; + + my $params = $c->request->params; + + return unless $params->{change_password}; + + unless ( $params->{new_password} ) { + $c->stash->{error_msg} = 'You must specify a new password'; + return; + } + + unless ( $params->{new_password_confirm} ) { + $c->stash->{error_msg} = 'You must fill in password confirm box as well'; + return; + } + + unless ( $params->{new_password_confirm} eq $params->{new_password} ) { + $c->stash->{error_msg} = 'new password and password confirm values do not match'; + return; + } + + $c->model('Golgi')->txn_do( + sub { + try{ + my $user = $c->model('Golgi')->change_user_password( + { id => $c->user->id, + new_password => $params->{new_password}, + new_password_confirm => $params->{new_password_confirm} + } + ); + + $c->flash->{success_msg} = 'Password successfully changed for: ' . $user->name ; + $c->res->redirect( $c->uri_for('/') ); + } + catch { + $c->stash->{error_msg} = 'Error encountered while changing password : ' . $_; + $c->model('Golgi')->txn_rollback; + }; + } + ); + + return; +} + +=head1 AUTHOR + +Sajith Perera + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +__PACKAGE__->meta->make_immutable; + +1; diff --git a/root/lib/navigation.tt b/root/lib/navigation.tt index d6a870f838..7779bbf723 100644 --- a/root/lib/navigation.tt +++ b/root/lib/navigation.tt @@ -1,15 +1,17 @@ -
+ +