Projet

Général

Profil

0002-wf-use-notification-api-multi-user-mode-60639.patch

Lauréline Guérin, 08 février 2022 17:11

Télécharger (4,67 ko)

Voir les différences:

Subject: [PATCH 2/3] wf: use notification api multi-user mode (#60639)

 tests/workflow/test_notification.py | 27 +++++++++++++++++----------
 wcs/wf/notification.py              | 26 +++++++++++++++-----------
 2 files changed, 32 insertions(+), 21 deletions(-)
tests/workflow/test_notification.py
71 71

  
72 72
    item.perform(formdata)
73 73
    assert http_requests.count() == 1
74
    assert http_requests.get_last('url') == 'https://portal/api/notification/add/?NameID=xxx'
74
    assert http_requests.get_last('url') == 'https://portal/api/notification/add/'
75 75
    assert json.loads(http_requests.get_last('body')) == {
76 76
        'body': 'XXX',
77 77
        'url': formdata.get_url(),
78 78
        'id': 'formdata:%s' % formdata.get_display_id(),
79 79
        'origin': '',
80 80
        'summary': 'xxx',
81
        'name_ids': ['xxx'],
81 82
    }
82 83

  
83 84
    # deleted user
......
108 109

  
109 110
    item.to = ['_receiver']
110 111
    item.perform(formdata)
111
    assert http_requests.count() == 2
112
    assert {x['url'] for x in http_requests.requests} == {
113
        'https://portal/api/notification/add/?NameID=xxy1',
114
        'https://portal/api/notification/add/?NameID=xxy2',
115
    }
112
    assert http_requests.count() == 1
113
    assert http_requests.get_last('url') == 'https://portal/api/notification/add/'
114
    assert set(json.loads(http_requests.get_last('body'))['name_ids']) == {'xxy1', 'xxy2'}
116 115

  
117 116
    # test inactive users are ignored
118 117
    user2.is_active = False
......
120 119
    http_requests.empty()
121 120
    item.perform(formdata)
122 121
    assert http_requests.count() == 1
123
    assert {x['url'] for x in http_requests.requests} == {'https://portal/api/notification/add/?NameID=xxy1'}
122
    assert http_requests.get_last('url') == 'https://portal/api/notification/add/'
123
    assert set(json.loads(http_requests.get_last('body'))['name_ids']) == {'xxy1'}
124

  
125
    user1.is_active = False
126
    user1.store()
127
    http_requests.empty()
128
    item.perform(formdata)
129
    assert http_requests.count() == 0
124 130

  
125 131
    # check notifications are sent to interco portal if it exists
132
    user1.is_active = True
133
    user1.store()
126 134
    pub.site_options.set('variables', '_interco_portal_url', 'https://interco-portal/')
127 135
    http_requests.empty()
128 136
    item.perform(formdata)
129 137
    assert http_requests.count() == 1
130
    assert {x['url'] for x in http_requests.requests} == {
131
        'https://interco-portal/api/notification/add/?NameID=xxy1'
132
    }
138
    assert http_requests.get_last('url') == 'https://interco-portal/api/notification/add/'
139
    assert set(json.loads(http_requests.get_last('body'))['name_ids']) == {'xxy1'}
wcs/wf/notification.py
137 137
            )
138 138
            return
139 139

  
140
        self.post_data = {
141
            'summary': title,
142
            'body': body,
143
            'url': formdata.get_url(),
144
            'origin': self.origin or '',
145
            'id': 'formdata:%s' % formdata.get_display_id(),
146
        }
147
        self.url = self.get_api_url()
148

  
149 140
        users = []
150 141
        for dest in self.to:
151 142
            if dest == '_submitter':
......
159 150
                    continue
160 151
                users.extend(get_publisher().user_class.get_users_with_role(role.id))
161 152

  
153
        name_ids = set()
162 154
        for user in users:
163 155
            if not user or not user.is_active or user.deleted_timestamp:
164 156
                continue
165 157
            for name_id in user.name_identifiers or []:
166
                self.qs_data = {'NameID': name_id}
167
                super().perform(formdata)
158
                name_ids.add(name_id)
159

  
160
        if name_ids:
161
            self.post_data = {
162
                'summary': title,
163
                'body': body,
164
                'url': formdata.get_url(),
165
                'origin': self.origin or '',
166
                'id': 'formdata:%s' % formdata.get_display_id(),
167
                'name_ids': list(name_ids),
168
            }
169
            self.url = self.get_api_url()
170

  
171
            super().perform(formdata)
168 172

  
169 173

  
170 174
register_item_class(SendNotificationWorkflowStatusItem)
171
-