Revision 0be81d73

b/Changelog
19 19
* Create 'snf_django' Python package to hold common code for all Synnefo
20 20
  components.
21 21
* CLOUDBAR_SERVICES_URL should point to /astakos/api/get_services
22
* CLOUDBAR_MENU_URL should point to /astakos/api/get_menu
23 22

  
24 23
Astakos
25 24
-------
b/docs/astakos-api-guide.rst
58 58
========================= =========  ==================
59 59
Uri                       Method     Description
60 60
========================= =========  ==================
61
``/astakos/api/get_menu`` GET        Get cloud bar menu
61
``/im/get_menu``          GET        Get cloud bar menu
62 62
========================= =========  ==================
63 63

  
64 64
Example reply if request user is not authenticated:
......
75 75
    {"url": "/im/landing", "name": "Dashboard"},
76 76
    {"url": "/im/logout", "name": "Sign out"}]
77 77

  
78
.. warning:: The service is also available under ``/im/get_menu``.
79
     It  will be removed in the next version.
80 78

  
81 79
User API Operations
82 80
--------------------
b/docs/quick-install-admin-guide.rst
612 612

  
613 613
    CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
614 614

  
615
    CLOUDBAR_MENU_URL = 'https://node1.example.com/astakos/api/get_menu'
615
    CLOUDBAR_MENU_URL = 'https://node1.example.com/im/get_menu'
616 616

  
617 617
Those settings have to do with the black cloudbar endpoints and will be
618 618
described in more detail later on in this guide. For now, just edit the domain
......
913 913
    CLOUDBAR_LOCATION = 'https://node1.example.com/static/im/cloudbar/'
914 914
    PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE = '3'
915 915
    CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
916
    CLOUDBAR_MENU_URL = 'https://node1.example.com/astakos/api/get_menu'
916
    CLOUDBAR_MENU_URL = 'https://node1.example.com/im/get_menu'
917 917

  
918 918
The ``CLOUDBAR_LOCATION`` tells the client where to find the astakos common
919 919
cloudbar.
......
1723 1723
   CLOUDBAR_LOCATION = 'https://node1.example.com/static/im/cloudbar/'
1724 1724
   CLOUDBAR_ACTIVE_SERVICE = '2'
1725 1725
   CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
1726
   CLOUDBAR_MENU_URL = 'https://account.node1.example.com/astakos/api/get_menu'
1726
   CLOUDBAR_MENU_URL = 'https://account.node1.example.com/im/get_menu'
1727 1727

  
1728 1728
``CLOUDBAR_LOCATION`` tells the client where to find the Astakos common
1729 1729
cloudbar. The ``CLOUDBAR_SERVICES_URL`` and ``CLOUDBAR_MENU_URL`` options are
b/docs/scale/i-astakos.rst
40 40

  
41 41
    CLOUDBAR_LOCATION = 'https://accounts.example.com/static/im/cloudbar/'
42 42
    CLOUDBAR_SERVICES_URL = 'https://accounts.example.com/astakos/api/get_services'
43
    CLOUDBAR_MENU_URL = 'https://accounts.example.com/astakos/api/get_menu'
43
    CLOUDBAR_MENU_URL = 'https://accounts.example.com/im/get_menu'
44 44

  
45 45
    ASTAKOS_IM_MODULES = ['local']
46 46

  
b/docs/scale/i-cms.rst
43 43
    CLOUDBAR_ACTIVE = True
44 44
    CLOUDBAR_LOCATION = 'https://accounts.example.com/static/im/cloudbar/'
45 45
    CLOUDBAR_SERVICES_URL = 'https://accounts.example.com/astakos/api/get_services'
46
    CLOUDBAR_MENU_URL = 'https://accounts.example.com/astakos/api/get_menu'
46
    CLOUDBAR_MENU_URL = 'https://accounts.example.com/im/get_menu'
47 47

  
48 48
    WEBPROJECT_SERVE_STATIC = True
49 49

  
b/docs/scale/i-pithos.rst
86 86

  
87 87
    CLOUDBAR_LOCATION = 'https://accounts.example.com/static/im/cloudbar/'
88 88
    CLOUDBAR_SERVICES_URL = 'https://accounts.example.com/astakos/api/get_services'
89
    CLOUDBAR_MENU_URL = 'https://accounts.example.com/astakos/api/get_menu'
89
    CLOUDBAR_MENU_URL = 'https://accounts.example.com/im/get_menu'
90 90

  
91 91
    PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE = 'XXXXXXXX'
92 92

  
b/docs/upgrade/upgrade-0.14.rst
79 79
=================================
80 80

  
81 81
In astakos-host edit ``/etc/synnefo/20-snf-astakos-app-cloudbar.conf`` and replace
82
the following lines:
82
the following line:
83 83

  
84 84
.. code-block:: console
85 85

  
86 86
    CLOUDBAR_SERVICES_URL = 'https://node1.example.com/im/get_services'
87
    CLOUDBAR_MENU_URL = 'https://node1.example.com/im/get_menu'
88 87

  
89 88
with:
90 89

  
91 90
.. code-block:: console
92 91

  
93 92
    CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
94
    CLOUDBAR_MENU_URL = 'https://node1.example.com/astakos/api/get_menu'
95 93

  
96 94
|
97 95

  
98 96
Also in pithos-host edit ``/etc/synnefo/20-snf-pithos-webclient-cloudbar.conf``
99
and the following lines:
97
and the following line:
100 98

  
101 99
.. code-block:: console
102 100

  
103 101
    CLOUDBAR_SERVICES_URL = 'https://node1.example.com/im/get_services'
104
    CLOUDBAR_MENU_URL = 'https://node1.example.com/im/get_menu'
105 102

  
106 103
with:
107 104

  
108 105
.. code-block:: console
109 106

  
110 107
    CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
111
    CLOUDBAR_MENU_URL = 'https://node1.example.com/astakos/api/get_menu'
112 108

  
113 109
|
114 110

  
115 111
Finally in cyclades-node edit ``/etc/synnefo/20-snf-cyclades-app-cloudbar.conf``
116
and replace the following lines:
112
and replace the following line:
117 113

  
118 114
.. code-block:: console
119 115

  
120 116
   CLOUDBAR_SERVICES_URL = 'https://node1.example.com/im/get_services'
121
   CLOUDBAR_MENU_URL = 'https://account.node1.example.com/im/get_menu'
122 117

  
123 118
with:
124 119

  
125 120
.. code-block:: console
126 121

  
127 122
   CLOUDBAR_SERVICES_URL = 'https://node1.example.com/astakos/api/get_services'
128
   CLOUDBAR_MENU_URL = 'https://account.node1.example.com/astakos/api/get_menu'
b/snf-astakos-app/astakos/api/__init__.py
77 77
        data = '%s(%s)' % (callback, data)
78 78

  
79 79
    return HttpResponse(content=data, mimetype=mimetype)
80

  
81

  
82
@api_method()
83
def get_menu(request, with_extra_links=False, with_signout=True):
84
    user = request.user
85
    index_url = reverse('index')
86

  
87
    if isinstance(user, User) and user.is_authenticated():
88
        l = []
89
        append = l.append
90
        item = MenuItem
91
        item.current_path = absolute(request, request.path)
92
        append(item(url=absolute(request, reverse('index')),
93
                    name=user.email))
94
        if with_extra_links:
95
            append(item(url=absolute(request, reverse('landing')),
96
                        name="Overview"))
97
        if with_signout:
98
            append(item(url=absolute(request, reverse('landing')),
99
                        name="Dashboard"))
100
        if with_extra_links:
101
            append(item(url=absolute(request, reverse('edit_profile')),
102
                        name="Profile"))
103

  
104
        if with_extra_links:
105
            if settings.INVITATIONS_ENABLED:
106
                append(item(url=absolute(request, reverse('invite')),
107
                            name="Invitations"))
108

  
109
            append(item(url=absolute(request, reverse('resource_usage')),
110
                        name="Usage"))
111

  
112
            if settings.PROJECTS_VISIBLE:
113
                append(item(url=absolute(request, reverse('project_list')),
114
                            name="Projects"))
115
            #append(item(
116
                #url=absolute(request, reverse('api_access')),
117
                #name="API Access"))
118

  
119
            append(item(url=absolute(request, reverse('feedback')),
120
                        name="Contact"))
121
        if with_signout:
122
            append(item(url=absolute(request, reverse('logout')),
123
                        name="Sign out"))
124
    else:
125
        l = [{'url': absolute(request, index_url),
126
              'name': _("Sign in")}]
127

  
128
    callback = request.GET.get('callback', None)
129
    data = json.dumps(tuple(l))
130
    mimetype = 'application/json'
131

  
132
    if callback:
133
        mimetype = 'application/javascript'
134
        data = '%s(%s)' % (callback, data)
135

  
136
    return HttpResponse(content=data, mimetype=mimetype)
137

  
138

  
139
class MenuItem(dict):
140
    current_path = ''
141

  
142
    def __init__(self, *args, **kwargs):
143
        super(MenuItem, self).__init__(*args, **kwargs)
144
        if kwargs.get('url') or kwargs.get('submenu'):
145
            self.__set_is_active__()
146

  
147
    def __setitem__(self, key, value):
148
        super(MenuItem, self).__setitem__(key, value)
149
        if key in ('url', 'submenu'):
150
            self.__set_is_active__()
151

  
152
    def __set_is_active__(self):
153
        if self.get('is_active'):
154
            return
155
        if self.current_path.startswith(self.get('url')):
156
            self.__setitem__('is_active', True)
157
        else:
158
            submenu = self.get('submenu', ())
159
            current = (i for i in submenu if i.get('url') == self.current_path)
160
            try:
161
                current_node = current.next()
162
                if not current_node.get('is_active'):
163
                    current_node.__setitem__('is_active', True)
164
                self.__setitem__('is_active', True)
165
            except StopIteration:
166
                return
167

  
168
    def __setattribute__(self, name, value):
169
        super(MenuItem, self).__setattribute__(name, value)
170
        if name == 'current_path':
171
            self.__set_is_active__()
b/snf-astakos-app/astakos/api/urls.py
36 36
urlpatterns = patterns(
37 37
    'astakos.api',
38 38
    url(r'^get_services/?$', 'get_services'),
39
    url(r'^get_menu/?$', 'get_menu'),
40 39
)
41 40

  
42 41
urlpatterns += patterns(
b/snf-astakos-app/astakos/im/context_processors.py
33 33

  
34 34
from astakos.im import settings
35 35
from astakos.im import presentation
36
from astakos.api import get_menu
36
from astakos.im.views import get_menu
37 37
from astakos.im.util import get_query
38 38
from astakos.im.auth_providers import PROVIDERS as AUTH_PROVIDERS
39 39

  
b/snf-astakos-app/astakos/im/urls.py
145 145
            'linkedin.authenticated'))
146 146

  
147 147
urlpatterns += patterns(
148
    'astakos.api',
149
    url(r'^get_services/?$', 'get_services'),
148
    'astakos.im.views',
150 149
    url(r'^get_menu/?$', 'get_menu'))
151 150

  
152 151
urlpatterns += patterns(
b/snf-astakos-app/astakos/im/views/im.py
41 41
from django.shortcuts import get_object_or_404
42 42
from django.contrib import messages
43 43
from django.contrib.auth.decorators import login_required
44
from django.contrib.auth.models import User
44 45
from django.core.urlresolvers import reverse
45 46
from django.db import transaction
46 47
from django.http import HttpResponse, HttpResponseRedirect, Http404
......
814 815
    return render_response(
815 816
        'im/api_access.html',
816 817
        context_instance=get_context(request))
818

  
819
@cookie_fix
820
def get_menu(request, with_extra_links=False, with_signout=True):
821
    user = request.user
822
    index_url = reverse('index')
823

  
824
    if isinstance(user, User) and user.is_authenticated():
825
        l = []
826
        append = l.append
827
        item = MenuItem
828
        item.current_path = request.build_absolute_uri(request.path)
829
        append(item(url=request.build_absolute_uri(reverse('index')),
830
                    name=user.email))
831
        if with_extra_links:
832
            append(item(url=request.build_absolute_uri(reverse('landing')),
833
                        name="Overview"))
834
        if with_signout:
835
            append(item(url=request.build_absolute_uri(reverse('landing')),
836
                        name="Dashboard"))
837
        if with_extra_links:
838
            append(item(url=request.build_absolute_uri(reverse('edit_profile')),
839
                        name="Profile"))
840

  
841
        if with_extra_links:
842
            if settings.INVITATIONS_ENABLED:
843
                append(item(url=request.build_absolute_uri(reverse('invite')),
844
                            name="Invitations"))
845

  
846
            append(item(url=request.build_absolute_uri(reverse('resource_usage')),
847
                        name="Usage"))
848

  
849
            if settings.PROJECTS_VISIBLE:
850
                append(item(url=request.build_absolute_uri(reverse('project_list')),
851
                            name="Projects"))
852

  
853
            append(item(url=request.build_absolute_uri(reverse('feedback')),
854
                        name="Contact"))
855
        if with_signout:
856
            append(item(url=request.build_absolute_uri(reverse('logout')),
857
                        name="Sign out"))
858
    else:
859
        l = [{'url': request.build_absolute_uri(index_url),
860
              'name': _("Sign in")}]
861

  
862
    callback = request.GET.get('callback', None)
863
    data = json.dumps(tuple(l))
864
    mimetype = 'application/json'
865

  
866
    if callback:
867
        mimetype = 'application/javascript'
868
        data = '%s(%s)' % (callback, data)
869

  
870
    return HttpResponse(content=data, mimetype=mimetype)
871

  
872

  
873
class MenuItem(dict):
874
    current_path = ''
875

  
876
    def __init__(self, *args, **kwargs):
877
        super(MenuItem, self).__init__(*args, **kwargs)
878
        if kwargs.get('url') or kwargs.get('submenu'):
879
            self.__set_is_active__()
880

  
881
    def __setitem__(self, key, value):
882
        super(MenuItem, self).__setitem__(key, value)
883
        if key in ('url', 'submenu'):
884
            self.__set_is_active__()
885

  
886
    def __set_is_active__(self):
887
        if self.get('is_active'):
888
            return
889
        if self.current_path.startswith(self.get('url')):
890
            self.__setitem__('is_active', True)
891
        else:
892
            submenu = self.get('submenu', ())
893
            current = (i for i in submenu if i.get('url') == self.current_path)
894
            try:
895
                current_node = current.next()
896
                if not current_node.get('is_active'):
897
                    current_node.__setitem__('is_active', True)
898
                self.__setitem__('is_active', True)
899
            except StopIteration:
900
                return
901

  
902
    def __setattribute__(self, name, value):
903
        super(MenuItem, self).__setattribute__(name, value)
904
        if name == 'current_path':
905
            self.__set_is_active__()
b/snf-astakos-app/conf/20-snf-astakos-app-cloudbar.conf
2 2
#CLOUDBAR_LOCATION = 'https://accounts.example.synnefo.org/static/im/cloudbar/'
3 3
#CLOUDBAR_COOKIE_NAME = '_pithos2_a'
4 4
#CLOUDBAR_SERVICES_URL = 'https://accounts.example.synnefo.org/astakos/api/get_services'
5
#CLOUDBAR_MENU_URL = 'https://accounts.example.synnefo.org/astakos/api/get_menu'
5
#CLOUDBAR_MENU_URL = 'https://accounts.example.synnefo.org/im/get_menu'
b/snf-common/synnefo/lib/context_processors.py
39 39
    CB_SERVICES_URL = getattr(settings, 'CLOUDBAR_SERVICES_URL',
40 40
            'https://accounts.okeanos.grnet.gr/astakos/api/get_services')
41 41
    CB_MENU_URL = getattr(settings, 'CLOUDBAR_MENU_URL',
42
            'https://accounts.okeanos.grnet.gr/astakos/api/get_menu')
42
            'https://accounts.okeanos.grnet.gr/im/get_menu')
43 43
    CB_HEIGHT = getattr(settings, 'CLOUDBAR_HEIGHT',
44 44
            '35')
45 45
    CB_BGCOLOR = getattr(settings, 'CLOUDBAR_BACKGROUND_COLOR',
b/snf-cyclades-app/conf/20-snf-cyclades-app-cloudbar.conf
3 3
#CLOUDBAR_COOKIE_NAME = '_pithos2_a'
4 4
#CLOUDBAR_ACTIVE_SERVICE = 'cloud'
5 5
#CLOUDBAR_SERVICES_URL = 'https://accounts.okeanos.grnet.gr/astakos/api/get_services'
6
#CLOUDBAR_MENU_URL = 'https://accounts.okeanos.grnet.gr/astakos/api/get_menu'
6
#CLOUDBAR_MENU_URL = 'https://accounts.okeanos.grnet.gr/im/get_menu'
7 7
#
b/snf-cyclades-app/synnefo/app_settings/default/cloudbar.py
3 3
CLOUDBAR_COOKIE_NAME = '_pithos2_a'
4 4
CLOUDBAR_ACTIVE_SERVICE = 'cloud'
5 5
CLOUDBAR_SERVICES_URL = 'https://accounts.synnefo.org/astakos/api/get_services'
6
CLOUDBAR_MENU_URL = 'https://accounts.synnefo.org/astakos/api/get_menu'
6
CLOUDBAR_MENU_URL = 'https://accounts.synnefo.org/im/get_menu'
7 7

  

Also available in: Unified diff