Commit 774408bd authored by Sofia Papagiannaki's avatar Sofia Papagiannaki

astakos: move get_menu service under astakos im services

get_menu is used only by astakos cloudbar:
it should not be under astakos api services
parent bb720f75
......@@ -19,7 +19,6 @@ Synnefo-wide
* Create 'snf_django' Python package to hold common code for all Synnefo
components.
* CLOUDBAR_SERVICES_URL should point to /astakos/api/get_services
* CLOUDBAR_MENU_URL should point to /astakos/api/get_menu
Astakos
-------
......
......@@ -58,7 +58,7 @@ Returns a json formatted list containing the cloud bar links.
========================= ========= ==================
Uri Method Description
========================= ========= ==================
``/astakos/api/get_menu`` GET Get cloud bar menu
``/im/get_menu`` GET Get cloud bar menu
========================= ========= ==================
Example reply if request user is not authenticated:
......@@ -75,8 +75,6 @@ Example reply if request user is authenticated:
{"url": "/im/landing", "name": "Dashboard"},
{"url": "/im/logout", "name": "Sign out"}]
.. warning:: The service is also available under ``/im/get_menu``.
It will be removed in the next version.
User API Operations
--------------------
......
......@@ -612,7 +612,7 @@ Then edit ``/etc/synnefo/20-snf-astakos-app-cloudbar.conf`` :
CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
CLOUDBAR_MENU_URL = 'https://node1.example.com/astakos/api/get_menu'
CLOUDBAR_MENU_URL = 'https://node1.example.com/im/get_menu'
Those settings have to do with the black cloudbar endpoints and will be
described in more detail later on in this guide. For now, just edit the domain
......@@ -913,7 +913,7 @@ pithos+ web UI with the astakos web UI (through the top cloudbar):
CLOUDBAR_LOCATION = 'https://node1.example.com/static/im/cloudbar/'
PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE = '3'
CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
CLOUDBAR_MENU_URL = 'https://node1.example.com/astakos/api/get_menu'
CLOUDBAR_MENU_URL = 'https://node1.example.com/im/get_menu'
The ``CLOUDBAR_LOCATION`` tells the client where to find the astakos common
cloudbar.
......@@ -1723,7 +1723,7 @@ Edit ``/etc/synnefo/20-snf-cyclades-app-cloudbar.conf``:
CLOUDBAR_LOCATION = 'https://node1.example.com/static/im/cloudbar/'
CLOUDBAR_ACTIVE_SERVICE = '2'
CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
CLOUDBAR_MENU_URL = 'https://account.node1.example.com/astakos/api/get_menu'
CLOUDBAR_MENU_URL = 'https://account.node1.example.com/im/get_menu'
``CLOUDBAR_LOCATION`` tells the client where to find the Astakos common
cloudbar. The ``CLOUDBAR_SERVICES_URL`` and ``CLOUDBAR_MENU_URL`` options are
......
......@@ -40,7 +40,7 @@ In `/etc/synnefo/astakos.conf` add:
CLOUDBAR_LOCATION = 'https://accounts.example.com/static/im/cloudbar/'
CLOUDBAR_SERVICES_URL = 'https://accounts.example.com/astakos/api/get_services'
CLOUDBAR_MENU_URL = 'https://accounts.example.com/astakos/api/get_menu'
CLOUDBAR_MENU_URL = 'https://accounts.example.com/im/get_menu'
ASTAKOS_IM_MODULES = ['local']
......
......@@ -43,7 +43,7 @@ In `/etc/synnefo/cloudcms.conf` add:
CLOUDBAR_ACTIVE = True
CLOUDBAR_LOCATION = 'https://accounts.example.com/static/im/cloudbar/'
CLOUDBAR_SERVICES_URL = 'https://accounts.example.com/astakos/api/get_services'
CLOUDBAR_MENU_URL = 'https://accounts.example.com/astakos/api/get_menu'
CLOUDBAR_MENU_URL = 'https://accounts.example.com/im/get_menu'
WEBPROJECT_SERVE_STATIC = True
......
......@@ -86,7 +86,7 @@ In `/etc/synnefo/webclient.conf` add:
CLOUDBAR_LOCATION = 'https://accounts.example.com/static/im/cloudbar/'
CLOUDBAR_SERVICES_URL = 'https://accounts.example.com/astakos/api/get_services'
CLOUDBAR_MENU_URL = 'https://accounts.example.com/astakos/api/get_menu'
CLOUDBAR_MENU_URL = 'https://accounts.example.com/im/get_menu'
PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE = 'XXXXXXXX'
......
......@@ -79,50 +79,44 @@ of pending applications per user::
=================================
In astakos-host edit ``/etc/synnefo/20-snf-astakos-app-cloudbar.conf`` and replace
the following lines:
the following line:
.. code-block:: console
CLOUDBAR_SERVICES_URL = 'https://node1.example.com/im/get_services'
CLOUDBAR_MENU_URL = 'https://node1.example.com/im/get_menu'
with:
.. code-block:: console
CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
CLOUDBAR_MENU_URL = 'https://node1.example.com/astakos/api/get_menu'
|
Also in pithos-host edit ``/etc/synnefo/20-snf-pithos-webclient-cloudbar.conf``
and the following lines:
and the following line:
.. code-block:: console
CLOUDBAR_SERVICES_URL = 'https://node1.example.com/im/get_services'
CLOUDBAR_MENU_URL = 'https://node1.example.com/im/get_menu'
with:
.. code-block:: console
CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
CLOUDBAR_MENU_URL = 'https://node1.example.com/astakos/api/get_menu'
|
Finally in cyclades-node edit ``/etc/synnefo/20-snf-cyclades-app-cloudbar.conf``
and replace the following lines:
and replace the following line:
.. code-block:: console
CLOUDBAR_SERVICES_URL = 'https://node1.example.com/im/get_services'
CLOUDBAR_MENU_URL = 'https://account.node1.example.com/im/get_menu'
with:
.. code-block:: console
CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
CLOUDBAR_MENU_URL = 'https://account.node1.example.com/astakos/api/get_menu'
......@@ -77,95 +77,3 @@ def get_services(request):
data = '%s(%s)' % (callback, data)
return HttpResponse(content=data, mimetype=mimetype)
@api_method()
def get_menu(request, with_extra_links=False, with_signout=True):
user = request.user
index_url = reverse('index')
if isinstance(user, User) and user.is_authenticated():
l = []
append = l.append
item = MenuItem
item.current_path = absolute(request, request.path)
append(item(url=absolute(request, reverse('index')),
name=user.email))
if with_extra_links:
append(item(url=absolute(request, reverse('landing')),
name="Overview"))
if with_signout:
append(item(url=absolute(request, reverse('landing')),
name="Dashboard"))
if with_extra_links:
append(item(url=absolute(request, reverse('edit_profile')),
name="Profile"))
if with_extra_links:
if settings.INVITATIONS_ENABLED:
append(item(url=absolute(request, reverse('invite')),
name="Invitations"))
append(item(url=absolute(request, reverse('resource_usage')),
name="Usage"))
if settings.PROJECTS_VISIBLE:
append(item(url=absolute(request, reverse('project_list')),
name="Projects"))
#append(item(
#url=absolute(request, reverse('api_access')),
#name="API Access"))
append(item(url=absolute(request, reverse('feedback')),
name="Contact"))
if with_signout:
append(item(url=absolute(request, reverse('logout')),
name="Sign out"))
else:
l = [{'url': absolute(request, index_url),
'name': _("Sign in")}]
callback = request.GET.get('callback', None)
data = json.dumps(tuple(l))
mimetype = 'application/json'
if callback:
mimetype = 'application/javascript'
data = '%s(%s)' % (callback, data)
return HttpResponse(content=data, mimetype=mimetype)
class MenuItem(dict):
current_path = ''
def __init__(self, *args, **kwargs):
super(MenuItem, self).__init__(*args, **kwargs)
if kwargs.get('url') or kwargs.get('submenu'):
self.__set_is_active__()
def __setitem__(self, key, value):
super(MenuItem, self).__setitem__(key, value)
if key in ('url', 'submenu'):
self.__set_is_active__()
def __set_is_active__(self):
if self.get('is_active'):
return
if self.current_path.startswith(self.get('url')):
self.__setitem__('is_active', True)
else:
submenu = self.get('submenu', ())
current = (i for i in submenu if i.get('url') == self.current_path)
try:
current_node = current.next()
if not current_node.get('is_active'):
current_node.__setitem__('is_active', True)
self.__setitem__('is_active', True)
except StopIteration:
return
def __setattribute__(self, name, value):
super(MenuItem, self).__setattribute__(name, value)
if name == 'current_path':
self.__set_is_active__()
......@@ -36,7 +36,6 @@ from django.conf.urls.defaults import patterns, url
urlpatterns = patterns(
'astakos.api',
url(r'^get_services/?$', 'get_services'),
url(r'^get_menu/?$', 'get_menu'),
)
urlpatterns += patterns(
......
......@@ -33,7 +33,7 @@
from astakos.im import settings
from astakos.im import presentation
from astakos.api import get_menu
from astakos.im.views import get_menu
from astakos.im.util import get_query
from astakos.im.auth_providers import PROVIDERS as AUTH_PROVIDERS
......
......@@ -145,8 +145,7 @@ if 'linkedin' in settings.IM_MODULES:
'linkedin.authenticated'))
urlpatterns += patterns(
'astakos.api',
url(r'^get_services/?$', 'get_services'),
'astakos.im.views',
url(r'^get_menu/?$', 'get_menu'))
urlpatterns += patterns(
......
......@@ -41,6 +41,7 @@ from urllib import quote
from django.shortcuts import get_object_or_404
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.db import transaction
from django.http import HttpResponse, HttpResponseRedirect, Http404
......@@ -814,3 +815,91 @@ def api_access(request):
return render_response(
'im/api_access.html',
context_instance=get_context(request))
@cookie_fix
def get_menu(request, with_extra_links=False, with_signout=True):
user = request.user
index_url = reverse('index')
if isinstance(user, User) and user.is_authenticated():
l = []
append = l.append
item = MenuItem
item.current_path = request.build_absolute_uri(request.path)
append(item(url=request.build_absolute_uri(reverse('index')),
name=user.email))
if with_extra_links:
append(item(url=request.build_absolute_uri(reverse('landing')),
name="Overview"))
if with_signout:
append(item(url=request.build_absolute_uri(reverse('landing')),
name="Dashboard"))
if with_extra_links:
append(item(url=request.build_absolute_uri(reverse('edit_profile')),
name="Profile"))
if with_extra_links:
if settings.INVITATIONS_ENABLED:
append(item(url=request.build_absolute_uri(reverse('invite')),
name="Invitations"))
append(item(url=request.build_absolute_uri(reverse('resource_usage')),
name="Usage"))
if settings.PROJECTS_VISIBLE:
append(item(url=request.build_absolute_uri(reverse('project_list')),
name="Projects"))
append(item(url=request.build_absolute_uri(reverse('feedback')),
name="Contact"))
if with_signout:
append(item(url=request.build_absolute_uri(reverse('logout')),
name="Sign out"))
else:
l = [{'url': request.build_absolute_uri(index_url),
'name': _("Sign in")}]
callback = request.GET.get('callback', None)
data = json.dumps(tuple(l))
mimetype = 'application/json'
if callback:
mimetype = 'application/javascript'
data = '%s(%s)' % (callback, data)
return HttpResponse(content=data, mimetype=mimetype)
class MenuItem(dict):
current_path = ''
def __init__(self, *args, **kwargs):
super(MenuItem, self).__init__(*args, **kwargs)
if kwargs.get('url') or kwargs.get('submenu'):
self.__set_is_active__()
def __setitem__(self, key, value):
super(MenuItem, self).__setitem__(key, value)
if key in ('url', 'submenu'):
self.__set_is_active__()
def __set_is_active__(self):
if self.get('is_active'):
return
if self.current_path.startswith(self.get('url')):
self.__setitem__('is_active', True)
else:
submenu = self.get('submenu', ())
current = (i for i in submenu if i.get('url') == self.current_path)
try:
current_node = current.next()
if not current_node.get('is_active'):
current_node.__setitem__('is_active', True)
self.__setitem__('is_active', True)
except StopIteration:
return
def __setattribute__(self, name, value):
super(MenuItem, self).__setattribute__(name, value)
if name == 'current_path':
self.__set_is_active__()
......@@ -2,4 +2,4 @@
#CLOUDBAR_LOCATION = 'https://accounts.example.synnefo.org/static/im/cloudbar/'
#CLOUDBAR_COOKIE_NAME = '_pithos2_a'
#CLOUDBAR_SERVICES_URL = 'https://accounts.example.synnefo.org/astakos/api/get_services'
#CLOUDBAR_MENU_URL = 'https://accounts.example.synnefo.org/astakos/api/get_menu'
#CLOUDBAR_MENU_URL = 'https://accounts.example.synnefo.org/im/get_menu'
......@@ -39,7 +39,7 @@ def cloudbar(request):
CB_SERVICES_URL = getattr(settings, 'CLOUDBAR_SERVICES_URL',
'https://accounts.okeanos.grnet.gr/astakos/api/get_services')
CB_MENU_URL = getattr(settings, 'CLOUDBAR_MENU_URL',
'https://accounts.okeanos.grnet.gr/astakos/api/get_menu')
'https://accounts.okeanos.grnet.gr/im/get_menu')
CB_HEIGHT = getattr(settings, 'CLOUDBAR_HEIGHT',
'35')
CB_BGCOLOR = getattr(settings, 'CLOUDBAR_BACKGROUND_COLOR',
......
......@@ -3,5 +3,5 @@
#CLOUDBAR_COOKIE_NAME = '_pithos2_a'
#CLOUDBAR_ACTIVE_SERVICE = 'cloud'
#CLOUDBAR_SERVICES_URL = 'https://accounts.okeanos.grnet.gr/astakos/api/get_services'
#CLOUDBAR_MENU_URL = 'https://accounts.okeanos.grnet.gr/astakos/api/get_menu'
#CLOUDBAR_MENU_URL = 'https://accounts.okeanos.grnet.gr/im/get_menu'
#
......@@ -3,5 +3,5 @@ CLOUDBAR_LOCATION = 'https://accounts.synnefo.org/static/im/cloudbar/'
CLOUDBAR_COOKIE_NAME = '_pithos2_a'
CLOUDBAR_ACTIVE_SERVICE = 'cloud'
CLOUDBAR_SERVICES_URL = 'https://accounts.synnefo.org/astakos/api/get_services'
CLOUDBAR_MENU_URL = 'https://accounts.synnefo.org/astakos/api/get_menu'
CLOUDBAR_MENU_URL = 'https://accounts.synnefo.org/im/get_menu'
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