Closed
Bug 622813
Opened 14 years ago
Closed 14 years ago
Provide user objects to email sending decision hook (bugmail_recipients)
Categories
(Bugzilla :: Extensions, enhancement)
Tracking
()
RESOLVED
FIXED
Bugzilla 4.2
People
(Reporter: gerv, Assigned: gerv)
Details
Attachments
(1 file, 2 obsolete files)
2.17 KB,
patch
|
mkanat
:
review+
|
Details | Diff | Splinter Review |
The problem: I want (or rather, b.m.o. wants) to, notwithstanding any other settings, block all email to addresses which end in ".tld" or ".bugs". We would like to do this using hooks/extensibility mechanisms.
I don't want to do this in the bugmail_recipients hook because that would require going through the recipients hash and creating user objects for each ID, so we could look at the login names. As Bugzilla is about to do that, in a loop, a bit further down the code, that seems very wasteful.
I guess I could also hand-roll some SQL to search for user ids in <set> which match <regexp> and then walk the data structure to remove them, but that seems icky too.
Two possible nicer solutions (I'm sure there are more):
1) Allow hooking Bugzilla::User::wants_bug_mail
2) Change mailer_before_send hook in some way which allows the hook to cancel
sending cleanly (at the moment it can only change the message)
Max? What solution would you prefer?
Gerv
![]() |
||
Comment 1•14 years ago
|
||
Why don't you simply turn on the disable_mail bit for all these user accounts?
Assignee | ||
Comment 2•14 years ago
|
||
Could do, but there's a lot of them, and people create new ones all the time, and it's a hassle to have to impersonate the user to disable the mail (and not everyone has that ability anyway) and currently we just solve the whole problem with a two-line patch to BugMail.pm. I'd just like to not have to do the two line patch.
Gerv
Comment 3•14 years ago
|
||
The bugmail_recipients hook is the time to decide who to send email to.
Perhaps a nicer solution would be to create user objects before the hook.
You could also have your extension override Bugzilla::User::disabledtext, although there might be times we search the DB directly for it too, in which case that wouldn't help.
Assignee | ||
Comment 4•14 years ago
|
||
We can create the User objects first, although we'd have to store them in a separate structure - which you might think is a little inelegant.
Like this:
my %users;
foreach my $id (keys %recipients) {
$users{$id} = new Bugzilla::User($id);
}
Bugzilla::Hook::process('bugmail_recipients',
{ bug => $bug, recipients => \%recipients,
diffs => $diffs, users => \%users });
...
foreach my $user_id (keys %recipients) {
my $user = $users{$id} || new Bugzilla::User($user_id);
Would that be acceptable?
Gerv
Comment 5•14 years ago
|
||
Hmm. Yes, as long as you use new_from_list instead of calling "new" in a loop, that should be fine. Also note that we already have %user_cache.
Assignee | ||
Updated•14 years ago
|
Summary: Allow hooking into decision about whether to send mail or not to a particular user → Provide user objects to email sending decision hook (bugmail_recipients)
Assignee | ||
Comment 6•14 years ago
|
||
Using new_from_list actually makes the code more complicated, because you have to extract a list of uncached users, call new_from_list, and then put the results back in the cache.
Gerv
Comment 7•14 years ago
|
||
Comment on attachment 501293 [details] [diff] [review]
Patch v.1
Oh, you're right. How about we just use "new"--after all, will there even ever be people in %recipients who aren't already in %user_cache?
Attachment #501293 -
Flags: review?(mkanat) → review-
Assignee | ||
Comment 8•14 years ago
|
||
Yes, there are certainly circumstances where that is true.
Here is a patch which adds a simple loop to make sure the cache is complete. It's not doing extra work because we need a user object for all these people eventually.
Gerv
Attachment #501293 -
Attachment is obsolete: true
Attachment #501331 -
Flags: review?(mkanat)
Comment 9•14 years ago
|
||
Comment on attachment 501331 [details] [diff] [review]
Patch v.2
Looks good to me. This needs a Bugzilla::Hook docs update now, also.
And why are you also adding "diffs" in this patch, isn't that a separate bug? (I have qualms about adding diffs that should be discussed elsewhere.)
Attachment #501331 -
Flags: review?(mkanat) → review-
Assignee | ||
Comment 10•14 years ago
|
||
Docs added, diffs removed. Bug 616422 is the bug about adding a reference to the diffs; I would love to hear your objections :-) BMO is certainly finding it necessary to know that information for its implementation of this hook.
Gerv
Attachment #501331 -
Attachment is obsolete: true
Attachment #501344 -
Flags: review?(mkanat)
Comment 11•14 years ago
|
||
Comment on attachment 501344 [details] [diff] [review]
Patch v.3
>+(But if you add additional recipients, you are not required to create and
>+add to this hash objects representing them.)
Fix on checkin:
(If you add additional recipients to the recipients hash, you are B<not> required to add them to this hash.)
Attachment #501344 -
Flags: review?(mkanat) → review+
Comment 12•14 years ago
|
||
Unfortunately, %user_cache doesn't exist on 4.0, so I can only approve this for trunk.
Flags: approval+
Target Milestone: --- → Bugzilla 4.2
Comment 13•14 years ago
|
||
Oh, and make that "to the C<recipients> hash"
Assignee | ||
Comment 14•14 years ago
|
||
Committing to: bzr+ssh://bzr.mozilla.org/bugzilla/trunk/
modified Bugzilla/BugMail.pm
modified Bugzilla/Hook.pm
Committed revision 7648.
Gerv
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•