Commit f7ed9c32 authored by Flavio TARSETTI's avatar Flavio TARSETTI

Merge branch '525-report-links-to-experiments' into 'master'

Smarter access logic for reports' experiments

Closes #525

See merge request !288
parents 155a644b 67e158e6
Pipeline #31964 passed with stage
in 15 minutes and 11 seconds
......@@ -50,6 +50,7 @@ class BasicReportSerializer(serializers.ModelSerializer):
content = serializers.SerializerMethodField()
author = serializers.SerializerMethodField()
experiments = serializers.SerializerMethodField()
experiment_access_map = serializers.SerializerMethodField()
analyzer = serializers.SerializerMethodField()
html_description = serializers.SerializerMethodField()
add_url = serializers.SerializerMethodField()
......@@ -86,6 +87,12 @@ class BasicReportSerializer(serializers.ModelSerializer):
def get_experiments(self, obj):
return map(lambda x: x.fullname(), obj.experiments.iterator())
def get_experiment_access_map(self, obj):
user = self.context['request'].user
access_map = list(map(lambda x: x.accessibility_for(user)[0],
obj.experiments.iterator()))
return access_map
def get_analyzer(self, obj):
if obj.analyzer is not None:
return obj.analyzer.fullname()
......@@ -118,7 +125,7 @@ class FullReportSerializer(BasicReportSerializer):
class Meta(BasicReportSerializer.Meta):
fields = ['name', 'number', 'short_description', 'description', 'is_owner', 'author','status', 'creation_date', 'publication_date', 'experiments', 'analyzer', 'content', 'html_description']
fields = ['name', 'number', 'short_description', 'description', 'is_owner', 'author','status', 'creation_date', 'publication_date', 'experiments', 'analyzer', 'content', 'html_description', 'experiment_access_map']
#----------------------------------------------------------
......
......@@ -27,7 +27,7 @@
* a table of experiments in the group, their databases/protocols, and aliases.
* Also has a menu for adding (compatible) experiments to the group.
*/
angular.module('reportApp').directive("groupPanelExperiments", ['GroupsService', 'ExperimentsService', 'UrlService', function(GroupsService, ExperimentsService, UrlService){
angular.module('reportApp').directive("groupPanelExperiments", ['GroupsService', 'ExperimentsService', 'UrlService', 'ReportService', function(GroupsService, ExperimentsService, UrlService, ReportService){
return {
scope: {
group: '='
......@@ -35,6 +35,7 @@ angular.module('reportApp').directive("groupPanelExperiments", ['GroupsService',
link: function(scope){
scope.experiments = ExperimentsService.experiments;
scope.dropdownId = `${scope.group.name}_exp_add_dropdown`;
scope.accessMap = ReportService.accessMap;
scope.getExpName = (expName) => scope.experiments[expName] ? expName : expName.split('/').pop();
const getExp = (expName) => scope.experiments[expName] || scope.experiments[expName.split('/').pop()];
......@@ -137,7 +138,10 @@ angular.module('reportApp').directive("groupPanelExperiments", ['GroupsService',
</td>
<td ng-if='!isViewmode()'><input ng-model='group.aliases[expName]' ng-model-options="{ debounce: 500 }"></input></td>
<td ng-if='isViewmode()'><span>{{ group.aliases[expName] }}</span></td>
<td><a href='{{ getExpUrl(expName) }}'>{{ getExpName(expName) }}</a></td>
<td>
<a ng-if='accessMap[expName]' href='{{ getExpUrl(expName) }}'>{{ getExpName(expName) }}</a>
<i ng-if='!accessMap[expName]'><small>experiment not accessible for current user</small></i>
</td>
<td>
<span ng-repeat='db in getExpDatabases(expName)'>
<a href='{{ getDatabaseUrl(db.split("@")[0]) }}'>{{ db }}</a>
......
......@@ -27,7 +27,7 @@
* manage this table's selected cols and float precision
*/
angular.module('reportApp')
.directive("groupTableItem", ['GroupsService', 'ExperimentsService', 'UrlService', function(GroupsService, ExperimentsService, UrlService){
.directive("groupTableItem", ['GroupsService', 'ExperimentsService', 'UrlService', 'ReportService', function(GroupsService, ExperimentsService, UrlService, ReportService){
return {
scope: {
group: '=',
......@@ -35,6 +35,8 @@ angular.module('reportApp')
content: '='
},
link: function(scope){
// access map for experiments
scope.accessMap = ReportService.accessMap;
// aliases
scope.fields = scope.content.fields;
// ids
......@@ -282,10 +284,10 @@ angular.module('reportApp')
<tbody>
<tr ng-repeat="exp in group.experiments | orderBy:sortFunc:sortField.isReversed">
<td ng-repeat='field in fields'>
<a ng-if='$index == 0 && getExperimentUrl(exp)' href='{{ getExperimentUrl(exp) }}'>
<a ng-if='$index == 0 && getExperimentUrl(exp) && accessMap[exp]' href='{{ getExperimentUrl(exp) }}'>
{{ getFieldVal(exp, field) }}
</a>
<span ng-if='!$index == 0 || !getExperimentUrl(exp)'>
<span ng-if='!$index == 0 || !getExperimentUrl(exp) || !accessMap[exp]'>
{{ getFieldVal(exp, field) }}
</span>
</td>
......
......@@ -50,6 +50,8 @@ angular.module('reportApp').factory('ReportService', ['GroupsService', 'plotterF
rs.number = report.number;
rs.author = report.author;
rs.name = report.name.split('/').length > 1 ? report.name.split('/')[1] : null;
rs.accessMap = report.experiments.reduce((o, expName, i) =>
({...o, [expName]: report.experiment_access_map[i]}), {});
// start up our GroupsService
GroupsService.loadGroups(report.content.groups);
......
......@@ -891,6 +891,7 @@ class EditableReportRetrievalTestCase(ReportTestCase):
"status": "editable",
"creation_date": self.report.creation_date.isoformat(),
"publication_date": None,
"experiment_access_map": [],
"experiments": [],
"content": {},
"analyzer": None,
......@@ -942,6 +943,7 @@ class LockedReportRetrievalTestCase(ReportTestCase):
"status": "locked",
"creation_date": self.report.creation_date.isoformat(),
"publication_date": None,
"experiment_access_map": [True],
"experiments": [self.experiment_analyzer1.fullname()],
"content": {},
"analyzer": None,
......@@ -989,6 +991,7 @@ class PublishedReportRetrievalTestCase(ReportTestCase):
"status": "published",
"creation_date": self.report.creation_date.isoformat(),
"publication_date": self.report.publication_date.isoformat(),
"experiment_access_map": [False],
"experiments": [self.experiment_analyzer1.fullname()],
"content": {},
"analyzer": None,
......@@ -1010,6 +1013,7 @@ class PublishedReportRetrievalTestCase(ReportTestCase):
"status": "published",
"creation_date": self.report.creation_date.isoformat(),
"publication_date": self.report.publication_date.isoformat(),
"experiment_access_map": [True],
"experiments": [self.experiment_analyzer1.fullname()],
"content": {},
"analyzer": None,
......@@ -1031,6 +1035,7 @@ class PublishedReportRetrievalTestCase(ReportTestCase):
"is_owner": False,
"author": self.johndoe.username,
"status": "published",
"experiment_access_map": [False],
"creation_date": self.report.creation_date.isoformat(),
"publication_date": self.report.publication_date.isoformat(),
"experiments": [self.experiment_analyzer1.fullname()],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment