def raise_invalid(self): if IDossierMarker.providedBy(self.context): mail_address = IEmailAddress( self.request).get_email_for_object(self.context) else: parent = aq_parent(aq_inner(self.context)) mail_address = IEmailAddress( self.request).get_email_for_object(parent) # Remove widget value in order to disable that the widget renders # radio-buttons (nochange/remove/replace) once a file has been # uploaded. # This is a special case since we are an additional validator # for the file field that may block an otherwise valid file upload. # The widget does not expect this to happen though. if getattr(self.view.parentForm, '_nullify_file_on_error', False): self.widget.value = None raise Invalid(_( u'error_mail_upload', default=(u"It's not possible to add E-mails here, please " "send it to ${mailaddress} or drag it to the dossier " "(Dragn'n'Drop)."), mapping={'mailaddress': mail_address} ))
def render(self): self.request.response.setHeader('Content-type', 'application/json') payloads = self.get_base_payloads() dossier_notifications = {} for payload in payloads: document = payload['document'] parent_dossier = document.get_parent_dossier() if (parent_dossier and IDossierMarker.providedBy(parent_dossier)): if parent_dossier.is_open(): payload['bcc'] = (IEmailAddress( self.request).get_email_for_object(parent_dossier)) parent_dossier_uuid = api.content.get_uuid(parent_dossier) if parent_dossier_uuid not in dossier_notifications: dossier_notifications[parent_dossier_uuid] = [] dossier_notifications[parent_dossier_uuid].append(document) payload['title'] = document.title_or_id() payload['content-type'] = document.get_file().contentType payload['download'] = document.get_download_view_name() payload['filename'] = document.get_filename() del payload['document'] notify(FileAttachedToEmailEvent(document)) for uuid, documents in dossier_notifications.iteritems(): dossier = api.content.get(UID=uuid) notify(DossierAttachedToEmailEvent(dossier, documents)) return json.dumps(payloads)
def validate_attach_payload(self, payload, document): content_type = payload.get('content-type', None) self.assertEquals(document.content_type(), content_type) csrf_token = payload.get('csrf-token', None) self.assertTrue(csrf_token) document_url = payload.get('document-url', None) self.assertEquals(document.absolute_url(), document_url) download = payload.get('download', None) self.assertEquals('download', download) filename = payload.get('filename', None) self.assertEquals(document.get_filename(), filename) title = payload.get('title', None) self.assertEquals(title, document.title_or_id()) parent_dossier = aq_parent(document) parent_dossier_state = api.content.get_state(parent_dossier) if parent_dossier_state == 'dossier-state-active': bcc = payload.get('bcc', None) dossier_bcc = IEmailAddress( self.request).get_email_for_object(parent_dossier) self.assertEquals(bcc, dossier_bcc)
def render(self): self.request.response.setHeader('Content-type', 'application/json') payloads = self.get_base_payloads() dossier_notifications = {} for payload in payloads: document = payload['document'] parent_dossier = document.get_parent_dossier() if parent_dossier: # XXX - this should be unnecessary with dossier journaling if parent_dossier.is_open(): payload['bcc'] = IEmailAddress( self.request).get_email_for_object(parent_dossier) parent_dossier_uuid = api.content.get_uuid(parent_dossier) if parent_dossier_uuid not in dossier_notifications: dossier_notifications[parent_dossier_uuid] = [] dossier_notifications[parent_dossier_uuid].append(document) payload['title'] = document.title_or_id() del payload['document'] notify(FileAttachedToEmailEvent(document)) for uuid, documents in dossier_notifications.iteritems(): dossier = api.content.get(UID=uuid) notify(DossierAttachedToEmailEvent(dossier, documents)) return json.dumps(payloads)
def test_mail_in_address_for_dossier(self): intid = self.intids.queryId(self.dossier) expected = "%s@%s" % (intid, self.mail_domain) adapter = IEmailAddress(self.request) mail_address = adapter.get_email_for_object(self.dossier) self.assertEquals(expected, mail_address)
def test_address_resolves_to_dossier(self): intid = self.intids.queryId(self.dossier) email_address = "%s@%s" % (intid, self.mail_domain) adapter = IEmailAddress(self.request) obj = adapter.get_object_for_email(email_address) self.assertEquals(self.dossier, obj)
def mailto_link(self): """Displays email-address if the IMailInAddressMarker behavior is provided and the dossier is Active""" if self.get_current_state() in DOSSIER_STATES_OPEN: address = IEmailAddress(self.request).get_email_for_object( self.context) return '<a href="mailto:%s">%s</a>' % (address, address)
def __call__(self, *args, **kwargs): result = super(SerializeDossierToJson, self).__call__(*args, **kwargs) result[u'reference_number'] = self.context.get_reference_number() result[u'email'] = IEmailAddress(self.request).get_email_for_object( self.context) return result
def test_mail_creation(self): dossier = create(Builder("dossier")) to_addess = IEmailAddress(self.request).get_email_for_object(dossier) message = self.MAIL_TEMPLATE.format(to_addess) obj = inbound.createMailInContainer(dossier, message) self.assertTrue(obj.preserved_as_paper) self.assertEqual(message, obj.message.data) self.assertEqual(MESSAGE_SOURCE_MAILIN, obj.message_source)
def test_raises_error_when_adding_mails_not_allowed(self): dossier = create(Builder("dossier")) dossier.manage_permission('ftw.mail: Add Inbound Mail', roles=[], acquire=False) to_addess = IEmailAddress(self.request).get_email_for_object(dossier) message = self.MAIL_TEMPLATE.format(to_addess) with self.assertRaises(Unauthorized): inbound.createMailInContainer(dossier, message)
def test_raises_error_when_mail_not_in_addable_types(self): ttool = api.portal.get_tool('portal_types') dossier_fti = ttool.get('opengever.dossier.businesscasedossier') dossier_fti.allowed_content_types = tuple() dossier = create(Builder("dossier")) to_addess = IEmailAddress(self.request).get_email_for_object(dossier) message = self.MAIL_TEMPLATE.format(to_addess) with self.assertRaises(ValueError): inbound.createMailInContainer(dossier, message)
def __call__(self, *args, **kwargs): result = super(SerializeDossierToJson, self).__call__(*args, **kwargs) result[u"responsible_fullname"] = self.context.get_responsible_actor( ).get_label(with_principal=False) result[u'reference_number'] = self.context.get_reference_number() result[u'email'] = IEmailAddress(self.request).get_email_for_object( self.context) result[u'is_subdossier'] = self.context.is_subdossier() return result
def test_service_contains_bcc_if_user_has_modify_portal_content_permission( self, browser): self.login(self.regular_user, browser) self.assertTrue( api.user.has_permission('Modify portal content', self.regular_user.getId(), obj=self.dossier)) browser.open(self.dossier, view='attributes', headers={'Accept': 'application/json'}) email = IEmailAddress(getRequest()).get_email_for_object(self.dossier) self.assertEquals({u'email': email}, browser.json)
def validate(self, value): """An mail upload as og.document should't be possible, it should be added as Mail object (see opengever.mail). """ if value and value.filename: basename, extension = os.path.splitext(value.filename) if extension.lower() in MAIL_EXTENSIONS: if IDossierMarker.providedBy(self.context): mail_address = IEmailAddress( self.request).get_email_for_object(self.context) else: parent = aq_parent(aq_inner(self.context)) mail_address = IEmailAddress( self.request).get_email_for_object(parent) raise Invalid( _(u'error_mail_upload', default=u"It's not possible to add E-mails here, please '\ 'send it to ${mailaddress} or drag it to the dossier '\ ' (Dragn'n'Drop).", mapping={'mailaddress': mail_address})) return
def test_p7m_mail_creation(self): dossier = create(Builder("dossier")) to_address = IEmailAddress(self.request).get_email_for_object(dossier) msg = email.message_from_string(load('signed.p7m')) msg.replace_header('To', to_address) message = msg.as_string() obj = inbound.createMailInContainer(dossier, message) self.assertTrue(obj.preserved_as_paper) self.assertEqual(message, obj.message.data) self.assertEqual(MESSAGE_SOURCE_MAILIN, obj.message_source) self.assertEqual('Hello.p7m', obj.message.filename) self.assertEqual('application/pkcs7-mime', obj.message.contentType)
def test_dossier_attributes(self): site_id = api.portal.get().id path_segments = [ s for s in self.dossier.getPhysicalPath() if s != site_id ] path_segments.append('attributes') dossier_attributes_path = '/'.join(path_segments) attributes = self.api.get(dossier_attributes_path).json() # Catch future changes to the API self.assertEqual(1, len(attributes.keys())) self.assertIn('email', attributes) dossier_email = IEmailAddress(self.request).get_email_for_object( self.dossier) self.assertEqual(dossier_email, attributes['email'])
def test_attach_to_outlook_payload_with_file_and_open_dossier( self, browser): # noqa self.enable_attach_to_outlook() payload = self.get_oc_url_jwt_decoded(self.doc_with_file_wf_open, 'attach') self.assertIn('documents', payload) self.assertIn(api.content.get_uuid(self.doc_with_file_wf_open), payload['documents']) self.assertIn('action', payload) self.assertEqual('attach', payload['action']) # Test we can actually fetch an action payload based on the JWT payload response = self.get_oc_payload_response(payload) self.assertEqual(200, response.status_code) payload = response.json() self.assertEqual(1, len(payload)) payload = payload[0] self.assertIn('bcc', payload) bcc = IEmailAddress(self.request).get_email_for_object( self.open_dossier) self.assertEqual(bcc, payload['bcc']) self.assertIn('title', payload) self.assertEqual(self.doc_with_file_wf_open.title_or_id(), payload['title']) # Test there is also a journal entry from the attach action browser.login() browser.open(self.doc_with_file_wf_open, view='tabbedview_view-journal') journal_entry = browser.css('.listing').first.lists()[1] self.assertEqual(journal_entry[1], 'Dokument mit Mailprogramm versendet') # Test there is also a journal entry in the dossier browser.login() browser.open(self.open_dossier, view='tabbedview_view-journal') journal_entry = browser.css('.listing').first.lists()[1] self.assertEqual(journal_entry[1], 'Dokument im Dossier mit Mailprogramm versendet')
def email(self): """Gets Email and display it in Byline""" mail_address = IEmailAddress(self.request ).get_email_for_object(self.context) return mail_address
def render(self): payload = {} payload['email'] = IEmailAddress(self.request).get_email_for_object( self.context) return json.dumps(payload)
def render(self): payload = {} if api.user.has_permission('Modify portal content', obj=self.context): payload['email'] = IEmailAddress( self.request).get_email_for_object(self.context) return json.dumps(payload)