diff --git a/beat/web/reports/serializers.py b/beat/web/reports/serializers.py index 8d70261f2c1b1538121d6275280676d59eeb1f76..158db1c814a3dd26cbf96c0a891588660c9a6704 100644 --- a/beat/web/reports/serializers.py +++ b/beat/web/reports/serializers.py @@ -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'] #---------------------------------------------------------- diff --git a/beat/web/reports/static/reports/app/directives/panelExperiments.js b/beat/web/reports/static/reports/app/directives/panelExperiments.js index c831da8272ad0bfa0cbf3e34752e01d3f2b690a7..adf5ca171c2c6123385024d11a5e2f46f5379c93 100644 --- a/beat/web/reports/static/reports/app/directives/panelExperiments.js +++ b/beat/web/reports/static/reports/app/directives/panelExperiments.js @@ -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,7 @@ 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></td> <td> <span ng-repeat='db in getExpDatabases(expName)'> <a href='{{ getDatabaseUrl(db.split("@")[0]) }}'>{{ db }}</a> diff --git a/beat/web/reports/static/reports/app/directives/tableItem.js b/beat/web/reports/static/reports/app/directives/tableItem.js index 99249203d1e3e7a3c7cad01f78dc2a371c5ecc3e..1a9cae99a0efb168e4d0f57728e9d2c9c30df0ce 100644 --- a/beat/web/reports/static/reports/app/directives/tableItem.js +++ b/beat/web/reports/static/reports/app/directives/tableItem.js @@ -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> diff --git a/beat/web/reports/static/reports/app/services/reportService.js b/beat/web/reports/static/reports/app/services/reportService.js index 90240945348a60332096885e2afe7fcc4197d8c2..cedaa6791717058199d133d166b2753b7ad5ae57 100644 --- a/beat/web/reports/static/reports/app/services/reportService.js +++ b/beat/web/reports/static/reports/app/services/reportService.js @@ -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);