Projet

Général

Profil

0001-publik-look-deeper-for-relevant-wcs-instance-7769.patch

Frédéric Péters, 15 juillet 2015 16:02

Télécharger (4,2 ko)

Voir les différences:

Subject: [PATCH] publik: look deeper for relevant wcs instance (#7769)

If there are several instances of wcs deployed (which is typical of a
multi-collectivity deployment) we ask authentic for user details so we
know where the user has been given roles, we can then get the relevant
wcs.
 combo/apps/publik/views.py            |  1 +
 data/themes/gadjo/static/js/publik.js | 46 +++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
combo/apps/publik/views.py
30 30
                'slug': service_slug,
31 31
                'service_id': service_id,
32 32
                'uniq': bool(len(services_dict) == 1),
33
                'url': service['url'],
33 34
                'backoffice_menu_url': service['backoffice-menu-url'],
34 35
                })
35 36
    response_body = 'var COMBO_KNOWN_SERVICES = %s;' % json.dumps(services)
data/themes/gadjo/static/js/publik.js
65 65
    create_menu_items();
66 66
  } else {
67 67
    var this_hostname = window.location.hostname;
68
    var look_for_wcs = false;
69
    var authentic_url = undefined;
70

  
68 71
    $(COMBO_KNOWN_SERVICES).each(function(index, element) {
69 72
      if (element.backoffice_menu_url === null) {
70 73
        element.data = Array();
......
77 80
         */
78 81
        var that_hostname = $('<a>').attr('href', element.backoffice_menu_url)[0].hostname;
79 82
        if (that_hostname != this_hostname) {
83
          look_for_wcs = true;
80 84
          element.data = Array();
81 85
          check_all_done();
82 86
          return;
83 87
        }
84 88
      }
85 89

  
90
      if (element.service_id === 'authentic') {
91
        authentic_url = element.url;
92
      }
93

  
86 94
      $.ajax({url: element.backoffice_menu_url,
87 95
            xhrFields: { withCredentials: true },
88 96
            async: true,
......
93 101
           }
94 102
       );
95 103
    });
104
    if (look_for_wcs && authentic_url) {
105
      /* if there is several wcs instances, we ask authentic for details on the
106
       * user, to get the services where the user has some roles
107
       */
108
      $.ajax({url: authentic_url + 'user_info/',
109
              xhrFields: { withCredentials: true },
110
              async: true,
111
              dataType: 'jsonp',
112
              crossDomain: true,
113
              success: function(data) {
114
                var services_to_consider = Array();
115
                /* iterate over all services, to get those to consider */
116
                $(COMBO_KNOWN_SERVICES).each(function(index, element) {
117
                  if (element.service_id !== 'wcs') return;
118
                  $(data.services).each(function(auth_index, auth_element) {
119
                    if (auth_element.slug !== element.slug) return;
120
                    if (auth_element.roles.length == 0) return;
121
                    services_to_consider.push(element);
122
                  });
123
                });
124
                if (services_to_consider.length == 1) {
125
                  /* only handle the case with a single service, for now */
126
                  var element = services_to_consider[0];
127
                  $.ajax({url: element.backoffice_menu_url,
128
                        xhrFields: { withCredentials: true },
129
                        async: true,
130
                        dataType: 'jsonp',
131
                        crossDomain: true,
132
                        success: function(data) { element.data = data; check_all_done(); },
133
                        error: function(error) { console.log('bouh', error); element.data = Array(); check_all_done(); }
134
                       }
135
                  );
136
                }
137
              },
138
              error: function(error) { console.log('bouh', error); }
139
             }
140
      );
141
    }
96 142
  }
97 143

  
98 144
  var sidepage_button = $('#sidepage #applabel');
99
-