From a3bc098cc1809172e670ff4e1c05f28e32217d7f Mon Sep 17 00:00:00 2001 From: Naama Menda Date: Sun, 17 Apr 2011 15:29:41 -0400 Subject: [PATCH] any user with db permissions should be able to call $metadata->store --- lib/CXGN/Chado/Stock.pm | 14 +++++++++++--- lib/CXGN/Metadata/Metadbdata.pm | 13 +++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/CXGN/Chado/Stock.pm b/lib/CXGN/Chado/Stock.pm index 7b5326e..48a1886 100644 --- a/lib/CXGN/Chado/Stock.pm +++ b/lib/CXGN/Chado/Stock.pm @@ -422,10 +422,18 @@ sub associate_allele { my $metadata = CXGN::Metadata::Metadbdata->new($metadata_schema); $metadata->set_create_person_id($sp_person_id); my $metadata_id = $metadata->store()->get_metadata_id(); - #store the image_id - stock_id link - my $q = "INSERT INTO phenome.stock_image (stock_id, image_id, metadata_id) VALUES (?,?,?) RETURNING stock_image_id"; + #check if the allele is already linked + my $ids = $self->get_schema->storage->dbh->selectcol_arrayref + ( "SELECT stock_allele_id FROM phenome.stock_allele WHERE stock_id = ? AND allele_id = ?", + undef, + $self->get_stock_id, + $allele_id + ); + if ($ids) { warn "Allele $allele_id is already linked with stock " . $self->get_stock_id ; } +#store the allele_id - stock_id link + my $q = "INSERT INTO phenome.stock_allele (stock_id, allele_id, metadata_id) VALUES (?,?,?) RETURNING stock_allele_id"; my $sth = $self->get_schema->storage->dbh->prepare($q); - $sth->execute($self->stock_id, $allele_id, $metadata_id); + $sth->execute($self->get_stock_id, $allele_id, $metadata_id); my ($id) = $sth->fetchrow_array; return $id; } diff --git a/lib/CXGN/Metadata/Metadbdata.pm b/lib/CXGN/Metadata/Metadbdata.pm index 8611fe8..e19ed08 100644 --- a/lib/CXGN/Metadata/Metadbdata.pm +++ b/lib/CXGN/Metadata/Metadbdata.pm @@ -1310,9 +1310,10 @@ sub store { ->dbh() ->selectrow_array("SELECT current_user"); - if ($user ne 'postgres') { - croak("USER ACCESS ERROR: Only postgres user can store data.\n"); - } + # should be open for any user with db permissions + #if ($user ne 'postgres') { + #croak("USER ACCESS ERROR: Only postgres user can store data.\n"); + #} my $metadata_row = $self->get_mdmetadata_row(); @@ -1376,13 +1377,13 @@ sub new_data_store { my $creation_user = $self->get_object_creation_user(); my $statement = "SELECT sp_person_id FROM sgn_people.sp_person WHERE username=?"; - my $creation_user_id = $self->get_schema() + my $creation_user_id = $self->get_create_person_id || $self->get_schema() ->storage() ->dbh() ->selectrow_array($statement, undef, ($creation_user)); - unless (defined $creation_user) { - my $error = "STORE ERROR: None creation user was supplied to CXGN::Metadata::Metadbdata object.\n"; + unless (defined $creation_user || defined $creation_user_id ) { + my $error = "STORE ERROR: No creation user nor id was supplied to CXGN::Metadata::Metadbdata object.\n"; $error .= " This parameter is a mandatory parameter for store functions\n"; croak($error); } -- 2.11.4.GIT