View Issue Details

IDProjectCategoryView StatusLast Update
0022225mantisbtfeaturepublic2017-02-20 04:47
Reporterkevcrou 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version2.0.0 
Target VersionFixed in Version 
Summary0022225: New Event to change email address of a user by project
Description

I'm currently developing a pluging to have generic users linked to multiple projects but having an email address different depending of the project the user is assigned on.

I use the normal user table and store the informations user_id, project_id and email in a plugin table

So I think that the simpliest way is to change what the user_api function return, when mantis try to get the email address, by the email address configured in my plugin.

To be in cohesion with mantis and to give better possibilities to futur plugin, I suggest to add a new event:

'EVENT_GET_USER_EMAIL' => EVENT_TYPE_DEFAULT, (something like that)

which may be send in user_api.php in user_get_field()
if $p_field_name equals 'email' => send event

What is your opinion on this ?

TagsNo tags attached.

Relationships

related to 0019977 new Add event "SENT_BUG_INFO_TO_ONE_USER" 

Activities

atrol

atrol

2017-01-20 09:00

developer   ~0055239

Last edited: 2017-01-20 18:16

View 2 revisions

Didn't have a deeper look, but this will introduce unwanted side effects.
I expect some confusion on pages My Account and Manage > Manage Users when trying to edit user e-mail settings

cproensa

cproensa

2017-01-20 13:27

developer   ~0055242

unwanted side effects.

also, may mess with login functions based on email

If it's intended to have more control over notifications, I suggest to work on the notification functionality
We already have plugin events
EVENT_NOTIFY_USER_INCLUDE
EVENT_NOTIFY_USER_EXCLUDE

Which works by allowing to include and exclude users in a notification process.
This has some pitfalls, which i remember stating before:

  • The included users by this event, are still checked against bug permissions, so it's still not possible to include an arbitrary user in the recipient list if it dont have access to the bug in the application
  • Recipient addresses come from the users, so an arbitrary email address cant be included if it's not associated to a user.

My proposal was, roughly:
Create a new event that processes a recipient list for a notification, where the plugin can then edit by adding or removing users or addresses.

This has to be detailed better, but as a start, i think would be a good addition that wont break any core functions, and allow implementation of several functionalities like:

  • Implementing a bcc recipient for all notifications
  • Implement a secondary address for users (managed by the plugin)
  • Adding external monitoring recipients that receive notifications.
kevcrou

kevcrou

2017-01-23 05:58

reporter   ~0055263

Thanks for your responses.

Your proposal seems to meet my needs so I looked in the code and I suggest something like that :

'EVENT_EMAIL_RECIPIENT' => EVENT_TYPE_CHAIN,

And for when to send the event I think email_store() in email_api.php is the best option :
$t_recipients = event_signal( 'EVENT_EMAIL_RECIPIENT', $t_recipients )

Is there others ways to send email than to pass throught email_store()?

I also saw email_collect_recipients() which better fit to your proposal but the problems are :

  • it's isn't called every time mantis send an email
  • it's called before others functions which retrieve again the email address throught the user_id.

What do you think about this ?

kevcrou

kevcrou

2017-02-01 10:22

reporter   ~0055440

Create a new event that processes a recipient list for a notification, where the plugin can then edit by adding or removing users or addresses.

I did the modification on my side with just these two lines.

I just changed the event signal to add the subject to the event and that give :

$t_recipients = event_signal( 'EVENT_EMAIL_RECIPIENT', $t_recipients, $t_subject )

And it's work fine in MD5 and LDAP configuration.

Can you consider adding this EVENT in the future ?

This has to be detailed better, but as a start, i think would be a good addition that wont break any core functions, and allow implementation of several functionalities like

  • Implementing a bcc recipient for all notifications
  • Implement a secondary address for users (managed by the plugin)
  • Adding external monitoring recipients that receive notifications.

As for the functionalities you proposed @cproensa I believe an EVENT with the EmailData object in parameter allow these implementations

My proposal :

In events_inc.php

'EVENT_EMAIL_READY_TO_SEND' => EVENT_TYPE_CHAIN,

In email_api.php->email_store() :

$t_email_data = event_signal( 'EVENT_EMAIL_READY_TO_SEND', $t_email_data );
$t_email_id = email_queue_add( $t_email_data );

it's can be used for

  • Coping the email and send it to another address
  • Checking email address before sending and apply a rule like if the address is anything@domain.something do not send or copy and send.
  • etc ...

If you prefer this option I can adapt my code without any problem.

I can also provide my plugin if you want but I precise that the users linked in my plugin are abstract and can represent differents entities depending of the project which is why I need an email address by project.
So that means these abstract users never connect to mantis.

kevcrou

kevcrou

2017-02-08 04:59

reporter   ~0055577

@atrol @cproensa Are you interested in my PR ?

atrol

atrol

2017-02-08 05:20

developer   ~0055578

@kevcrou certainly interested, but no time to have a look at it.

kevcrou

kevcrou

2017-02-08 09:18

reporter   ~0055581

PR : https://github.com/mantisbt/mantisbt/pull/1022

dlm

dlm

2017-02-17 04:21

reporter   ~0055716

Hi all,

@kevcrou I am interested in that plugin. Do you plan to share it ?
@atrol @cproensa Do you think the new event addition can be merged ?

kevcrou

kevcrou

2017-02-20 04:47

reporter   ~0055724

Hi dlm,

I'm glad that you're interested in my work so I left it in attachement.

Since my PR is not accepted yet, to use this plugin you have to modify the code just like it's done in the PR in the above post.



GenericUsers.zip (27,490 bytes)

Issue History

Date Modified Username Field Change
2017-01-20 08:28 kevcrou New Issue
2017-01-20 09:00 atrol Note Added: 0055239
2017-01-20 13:27 cproensa Note Added: 0055242
2017-01-20 18:16 atrol Note Edited: 0055239 View Revisions
2017-01-23 05:58 kevcrou Note Added: 0055263
2017-01-24 16:48 atrol Relationship added related to 0019977
2017-02-01 10:22 kevcrou Note Added: 0055440
2017-02-08 04:59 kevcrou Note Added: 0055577
2017-02-08 05:20 atrol Note Added: 0055578
2017-02-08 09:18 kevcrou Note Added: 0055581
2017-02-17 04:21 dlm Note Added: 0055716
2017-02-20 04:47 kevcrou File Added: GenericUsers.zip
2017-02-20 04:47 kevcrou Note Added: 0055724