Projet

Général

Profil

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

Frédéric Péters, 08 juillet 2015 09:16

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

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