Skip to content

Commit

Permalink
fixing curator and breeder privileges
Browse files Browse the repository at this point in the history
  • Loading branch information
chris263 committed Nov 24, 2024
1 parent 08404dc commit eec5c94
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 42 deletions.
17 changes: 10 additions & 7 deletions js/source/entries/qualitycontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export function init(main_div) {
console.log("AJAX response:", r); // Log full response for debugging

if (r.selected_variable) {
console.log("Selected Variable HTML:", r.selected_variable); // Debugging log
populateTraitDropdown(r.selected_variable); // Populate dropdown with traits
}
if (r.tempfile) {
Expand Down Expand Up @@ -127,7 +126,6 @@ export function init(main_div) {
const result = drawBoxplot(r.data, trait_selected, outlierMultiplier );
outliers = result.outliers; // Extract the outliers
allData = r.data;
console.log("here outliers", outliers);
populateOutlierTable(r.data, trait_selected);
populateCleanTable(r.data, outliers, trait_selected);
}
Expand All @@ -147,8 +145,15 @@ export function init(main_div) {
data: {"outliers": JSON.stringify(outliers),
},
success: function(response) {
alert('Outliers saved successfully!');
console.log(response);
if(response.is_curator === 1) {
$('#store_outliers_button').prop("disabled", false);
alert('Outliers successfully stored!');
} else {
$('#store_outliers_button').prop("disabled", true);
alert("Only curators or breeders are allowed to validated trials. Please contact a curator.", response.is_curator);
}


},
error: function(xhr, status, error) {
alert('Error saving outliers: ' + error);
Expand All @@ -168,17 +173,15 @@ export function init(main_div) {
return;
} else {
var trialNames = r.data;
console.log("Outliers to restore:", trialNames);
$.ajax({
url: '/ajax/qualitycontrol/restoreoutliers',
method: "POST",
data: {"outliers": JSON.stringify(trialNames), "trait":trait_selected,
},
success: function (r) {
console.log("The curator is:", r.is_curator);
if (r.is_curator === 1) {
$('#restore_outliers_button').prop("disabled", false);
console.log("Restore successful!");
alert("Data successfully restored!");
} else {
$('#restore_outliers_button').prop("disabled", true);
alert("Only curators are allowed undo validated trial. Please contact a curator.");
Expand Down
78 changes: 44 additions & 34 deletions lib/SGN/Controller/AJAX/QualityControl.pm
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,15 @@ sub store_outliers : Path('/ajax/qualitycontrol/storeoutliers') Args(0) {

my $schema = $c->dbic_schema("Bio::Chado::Schema", undef, $sp_person_id);

my @user_roles = $c->user()->roles;
my $curator = (grep { $_ eq 'curator' || $_ eq 'breeder' } @user_roles) ? 1 : 0;

my $response_data = {
is_curator => $curator ? 1 : 0, # 1 if curator, 0 otherwise
};


# Retrieve and decode the outliers from the request

my $outliers_string = $c->req->param('outliers');

# Now proceed to decode JSON
Expand Down Expand Up @@ -282,11 +289,9 @@ sub store_outliers : Path('/ajax/qualitycontrol/storeoutliers') Args(0) {
my @unique_trait_ids = grep { !$seen{$_}++ } values %trait_ids;
my $trait_ids_sql = join(", ", @unique_trait_ids);

# Ensure plot names and traits are not empty

print("Plot names:\n");
if (@plot_names && %trait_ids) {
print STDERR Dumper \@plot_names;
# print STDERR Dumper \@plot_names;
# Convert plot names and traits into comma-separated lists for SQL
my $plot_names_sql = join(", ", map { $schema->storage->dbh()->quote($_) } @plot_names);

Expand All @@ -310,26 +315,26 @@ sub store_outliers : Path('/ajax/qualitycontrol/storeoutliers') Args(0) {
AND phenotypeprop.type_id = (SELECT cvterm_id FROM cvterm WHERE name = 'phenotype_outlier')
);";

# Execute the SQL query
eval {
my $sth_trial = $schema->storage->dbh->prepare($trial_sql);
$sth_trial->execute();

my $sth_outliers = $schema->storage->dbh->prepare($outlier_data_sql);
$sth_outliers->execute();

$c->response->body('Data stored successfully');
};
if ($@) {
$c->response->body("Failed to store data: $@");
return;
if($curator == 1){
# Execute the SQL query
eval {
my $sth_trial = $schema->storage->dbh->prepare($trial_sql);
$sth_trial->execute();

my $sth_outliers = $schema->storage->dbh->prepare($outlier_data_sql);
$sth_outliers->execute();

$c->stash->{rest} = $response_data;
};
} else {
$c->response->body('Outliers stored successfully');
$c->stash->{rest} = $response_data;

}

} else {
$c->response->body('No plot names or traits found.');
}


## celaning tempfiles
rmtree(File::Spec->catfile($c->config->{basepath}, "static/documents/tempfiles/qualitycontrol"));
}
Expand All @@ -343,6 +348,7 @@ sub restore_outliers : Path('/ajax/qualitycontrol/restoreoutliers') Args(0) {
my @user_roles = $c->user()->roles;

my $curator = (grep { $_ eq 'curator' } @user_roles) ? 'curator' : undef;


# Retrieve and decode the outliers from the request
my $outliers_string = $c->req->param('outliers');
Expand All @@ -355,9 +361,10 @@ sub restore_outliers : Path('/ajax/qualitycontrol/restoreoutliers') Args(0) {

my $trait_like = $trait . '%';

print("******************************************************************\n");
print($trait_like);

my $response_data = {
is_curator => $curator ? 1 : 0, # 1 if curator, 0 otherwise
};

my $trial_clean_sql = qq{
DELETE FROM projectprop
WHERE projectprop.project_id IN (
Expand Down Expand Up @@ -388,25 +395,28 @@ sub restore_outliers : Path('/ajax/qualitycontrol/restoreoutliers') Args(0) {
);
};

my $response_data = {
is_curator => $curator ? 1 : 0, # 1 if curator, 0 otherwise
};


# Execute the SQL query
eval {
if ($curator eq 'curator'){
eval {
my $sth_trial = $dbh->prepare($trial_clean_sql);
$sth_trial->execute();

my $sth_trial = $dbh->prepare($trial_clean_sql);
$sth_trial->execute();
my $sth_clean = $dbh->prepare($outliers_clean_sql);
$sth_clean->execute();
};

my $sth_clean = $dbh->prepare($outliers_clean_sql);
$sth_clean->execute();
};
if ($@) {
$c->response->body("Failed to store data: $@");
return;
if ($@) {
$c->response->body("Failed to store data: $@");
return;
} else {
$c->stash->{rest} = $response_data;
}
} else {
$c->stash->{rest} = $response_data;
}

## celaning tempfiles
rmtree(File::Spec->catfile($c->config->{basepath}, "static/documents/tempfiles/qualitycontrol"));

Expand Down
3 changes: 2 additions & 1 deletion mason/tools/qualityControl/dataset_quality_control.mas
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@
<div>
<div style="text-align: center;">
<p>This is the validation process. Trials cleaned of outliers can be used in downstream analysis.</p>
<p>Only <b>CURATORS</b> are allowed to restore all original data.</p>
<p>To validate a dataset you will need privilieges as <b>CURATOR</b> or <b>BREEDER</b>.</p>
<p>Only <b>CURATORS</b> are allowed to restore the dataset to original values.</p>
<button class="btn btn-main" id="restore_outliers_button" onclick="Workflow.complete(this);">Restore</button>
<button class="btn btn-main" id="store_outliers_button" onclick="Workflow.complete(this);">Validate</button>
</div>
Expand Down

0 comments on commit eec5c94

Please sign in to comment.