diff --git a/beat/web/plotters/api.py b/beat/web/plotters/api.py index eb27a9970bb835e9e3d80c6303ae66d8529dea2a..7136f46a2974c337cf2d1892f04588c32cffd3f5 100644 --- a/beat/web/plotters/api.py +++ b/beat/web/plotters/api.py @@ -124,12 +124,12 @@ class CheckPlotterNameView(CheckContributionNameView): #---------------------------------------------------------- -class SharePlotterView(ShareCodeView): +class SharePlotterParameterView(ShareCodeView): """ - This view allows to share a plotter with + This view allows to share a plotterparameter with other users and/or teams """ - model = Plotter + model = PlotterParameter #---------------------------------------------------------- diff --git a/beat/web/plotters/api_urls.py b/beat/web/plotters/api_urls.py index da670548bdea0ffe89912523caa3a9508952e949..7786cbd60657ded7a957ec752be1b84a249f9274 100644 --- a/beat/web/plotters/api_urls.py +++ b/beat/web/plotters/api_urls.py @@ -32,6 +32,12 @@ from . import api urlpatterns = [ url(r'^$', api.ListPlotterView.as_view(), name='all'), url(r'^format/(?P<author_name>\w+)/(?P<dataformat_name>[a-zA-Z0-9_\-]+)/(?P<version>\d+)/$', api.ListFormatPlotterView.as_view(), name='object'), + + url(r'^plotterparameters/(?P<author_name>\w+)/(?P<object_name>[a-zA-Z0-9_\-]+)/(?P<version>\d+)/share/$', + api.SharePlotterParameterView.as_view(), + name='share', + ), + url(r'^plotterparameters/(?P<author_name>\w+)/(?P<object_name>[a-zA-Z0-9_\-]+)/(?P<version>\d+)/$', api.RetrieveUpdateDestroyPlotterParametersView.as_view(), name='view'), url(r'^plotterparameters/(?P<author_name>\w+)/$', api.ListPlotterParametersView.as_view(), name='view'), url(r'^plotterparameters/$', api.ListPlotterParameterView.as_view(), name='all_plotterparameter'), @@ -53,10 +59,6 @@ urlpatterns = [ # name='diff', # ), - url(r'^(?P<author_name>\w+)/(?P<object_name>[-\w]+)/(?P<version>\d+)/share/$', - api.SharePlotterView.as_view(), - name='share', - ), url(r'^(?P<author_name>\w+)/$', api.ListCreatePlottersView.as_view(), diff --git a/beat/web/plotters/apps.py b/beat/web/plotters/apps.py index a4f7a101dfcdd331438dbec9ddb559172c3f4e22..337c13161194efcd829bddaf99c1286a4be60279 100644 --- a/beat/web/plotters/apps.py +++ b/beat/web/plotters/apps.py @@ -36,3 +36,4 @@ class PlottersConfig(CommonAppConfig): super(PlottersConfig, self).ready() from actstream import registry registry.register(self.get_model('Plotter')) + registry.register(self.get_model('PlotterParameter')) diff --git a/beat/web/plotters/models.py b/beat/web/plotters/models.py index 6dfc85c65f5cf6e74293e00014dd5068bf9b9d26..03da7c3964bc78d9878b7ddeb20b675ca7877733 100755 --- a/beat/web/plotters/models.py +++ b/beat/web/plotters/models.py @@ -295,6 +295,14 @@ class PlotterParameter(Contribution): ) + def get_api_share_url(self): + '''Returns the endpoint to share this object''' + + return reverse( + 'api_plotters:share', + args=(self.author.username, self.name, self.version,), + ) + class DefaultPlotter(models.Model): diff --git a/beat/web/plotters/templates/plotterparameters/plotterparameter.html b/beat/web/plotters/templates/plotterparameters/plotterparameter.html index 331819267eccc438bda33d44727f5cb8056bebb8..7a55221f36ef9455e085a9ce7286ae9f8ab9529e 100644 --- a/beat/web/plotters/templates/plotterparameters/plotterparameter.html +++ b/beat/web/plotters/templates/plotterparameters/plotterparameter.html @@ -242,9 +242,7 @@ </div> {% if owner %} <div role="tabpanel" class="tab-pane" id="sharing"> -{% comment %} {% plotterparameter_sharing plotterparameter %} -{% endcomment %} </div> {% endif %} <div role="tabpanel" class="tab-pane" id="reports"> diff --git a/beat/web/plotters/templatetags/plotter_tags.py b/beat/web/plotters/templatetags/plotter_tags.py index 71514434743956ab4f6c3475961f9bf2ee71aa0e..fa8c5828e3074ab498836ba55ba9a008d6f92f2a 100644 --- a/beat/web/plotters/templatetags/plotter_tags.py +++ b/beat/web/plotters/templatetags/plotter_tags.py @@ -242,6 +242,25 @@ def plotterparameter_actions(context, object, display_count): ) +@register.inclusion_tag('plotterparameters/panels/sharing.html', takes_context=True) +def plotterparameter_sharing(context, obj): + '''Composes the current sharing properties and a form to change them + + Parameters: + + obj (plotter): The plotter object concerned for which the + sharing panel will be drawn + + ''' + return { + 'request': context['request'], + 'object': obj, + 'owner': context['request'].user == obj.author, + 'users': context['users'], + 'teams': context['teams'], + } + + @register.inclusion_tag('plotters/panels/sharing.html', takes_context=True) def plotter_sharing(context, obj): '''Composes the current sharing properties and a form to change them diff --git a/beat/web/plotters/views.py b/beat/web/plotters/views.py index 32fc2d41e61b690c60296617fcf6c75e09dfe2ab..7469b4e8c7c5ff473fa950d0474cdb6e84660885 100644 --- a/beat/web/plotters/views.py +++ b/beat/web/plotters/views.py @@ -719,11 +719,22 @@ def plotterparameter_for_author(request, author_name, plotterparameter_name, ver name = plotterparameter_name, version = version) + (has_access, accessibility) = obj.accessibility_for(request.user) + + if not has_access: raise Http404() + + owner = (request.user == obj.author) + + # Users the object can be shared with + users = User.objects.exclude(username__in=settings.ACCOUNTS_TO_EXCLUDE_FROM_TEAMS).order_by('username') + return render_to_response('plotterparameters/plotterparameter.html', { 'author' : author_name, 'plotterparameter_name' : plotterparameter_name, 'owner' : (request.user == obj.author), + 'users': users, + 'teams': Team.objects.for_user(request.user, True), 'plotterparameter' : obj, 'USE_HTTPS_GRAVATAR': settings.USE_HTTPS_GRAVATAR, },