summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'extensions')
-rw-r--r--extensions/ComponentWatching/Extension.pm60
-rw-r--r--extensions/ComponentWatching/template/en/default/hook/admin/components/edit-common-rows.html.tmpl52
-rw-r--r--extensions/ComponentWatching/template/en/default/hook/global/messages-component_updated_fields.html.tmpl3
3 files changed, 112 insertions, 3 deletions
diff --git a/extensions/ComponentWatching/Extension.pm b/extensions/ComponentWatching/Extension.pm
index 38b1abb3c..0af1ae6cf 100644
--- a/extensions/ComponentWatching/Extension.pm
+++ b/extensions/ComponentWatching/Extension.pm
@@ -18,6 +18,9 @@ use Bugzilla::Util qw(trim trick_taint);
our $VERSION = '2';
+use constant REQUIRE_WATCH_USER => 1;
+use constant DEFAULT_ASSIGNEE => 'nobody@mozilla.org';
+
use constant REL_COMPONENT_WATCHER => 15;
#
@@ -112,6 +115,12 @@ sub template_before_create {
$constants->{REL_COMPONENT_WATCHER} = REL_COMPONENT_WATCHER;
}
+sub template_before_process {
+ my ($self, $args) = @_;
+ return unless $args->{file} eq 'admin/components/create.html.tmpl';
+ $args->{vars}{comp}{default_assignee}{login} = DEFAULT_ASSIGNEE;
+}
+
#
# user-watch
#
@@ -147,6 +156,7 @@ sub object_update_columns {
# editcomponents.cgi doesn't call set_all, so we have to do this here
my $input = Bugzilla->input_params;
$object->set('watch_user', $input->{watch_user});
+ $self->_create_watch_user();
}
sub object_validators {
@@ -180,6 +190,7 @@ sub object_before_create {
else {
my $input = Bugzilla->input_params;
$params->{watch_user} = $input->{watch_user};
+ $self->_create_watch_user();
}
}
@@ -192,14 +203,59 @@ sub object_end_of_update {
my $old_id = $old_object->watch_user ? $old_object->watch_user->id : 0;
my $new_id = $object->watch_user ? $object->watch_user->id : 0;
- return if $old_id == $new_id;
+ if ($old_id != $new_id) {
+ $changes->{watch_user} = [ $old_id ? $old_id : undef, $new_id ? $new_id : undef ];
+ }
+
+ # when a component is renamed, update the watch-user to follow
+ # this only happens when the user appears to have been auto-generated from the old name
+ if ($changes->{name}
+ && $old_object->watch_user
+ && $object->watch_user
+ && $old_object->watch_user->id == $object->watch_user->id
+ && _generate_watch_user_name($old_object) eq $object->watch_user->login
+ )
+ {
+ my $old_login = $object->watch_user->login;
+ $object->watch_user->set_login(_generate_watch_user_name($object));
+ $object->watch_user->update();
+ $changes->{watch_user_login} = [ $old_login, $object->watch_user->login ];
+ }
+}
- $changes->{watch_user} = [ $old_id ? $old_id : undef, $new_id ? $new_id : undef ];
+sub _generate_watch_user_name {
+ # this is mirrored in template/en/default/hook/admin/components/edit-common-rows.html.tmpl
+ # that javascript needs to be kept in sync with this perl
+ my ($component) = @_;
+ return _sanitise_name($component->name)
+ . '@' . _sanitise_name($component->product->name) . '.bugs';
+}
+
+sub _sanitise_name {
+ my ($name) = @_;
+ $name = lc($name);
+ $name =~ s/[^a-z0-9_]/-/g;
+ $name =~ s/-+/-/g;
+ $name =~ s/(^-|-$)//g;
+ return $name;
+}
+
+sub _create_watch_user {
+ my $input = Bugzilla->input_params;
+ if ($input->{watch_user_auto}
+ && !Bugzilla::User->new({ name => $input->{watch_user} }))
+ {
+ Bugzilla::User->create({
+ login_name => $input->{watch_user},
+ cryptpassword => '*',
+ });
+ }
}
sub _check_watch_user {
my ($self, $value, $field) = @_;
$value = trim($value || '');
+ return undef if !REQUIRE_WATCH_USER && $value eq '';
if ($value eq '') {
ThrowUserError('component_watch_missing_watch_user');
}
diff --git a/extensions/ComponentWatching/template/en/default/hook/admin/components/edit-common-rows.html.tmpl b/extensions/ComponentWatching/template/en/default/hook/admin/components/edit-common-rows.html.tmpl
index 4f92097ff..e6a04f092 100644
--- a/extensions/ComponentWatching/template/en/default/hook/admin/components/edit-common-rows.html.tmpl
+++ b/extensions/ComponentWatching/template/en/default/hook/admin/components/edit-common-rows.html.tmpl
@@ -9,12 +9,62 @@
<tr>
<th class="field_label"><label for="watch_user">Watch User:</label></th>
<td>
+ [% IF !comp.id || !comp.watch_user %]
+ <input type="checkbox" id="watch_user_auto" name="watch_user_auto" value="1" checked>
+ <label for="watch_user_auto">Automatic</label>
+ <span id="watch_user_suggestion"></span>
+ [% edit_size = 44 %]
+ [% ELSE %]
+ [% edit_size = 64 %]
+ [% END %]
[% INCLUDE global/userselect.html.tmpl
name => "watch_user"
id => "watch_user"
value => comp.watch_user.login
- size => 64
+ size => edit_size
emptyok => 1
%]
</td>
</tr>
+
+<script>
+function sanitise_name(name) {
+ return name.toLowerCase()
+ .replace(/[^a-z0-9_]/g, '-')
+ .replace(/-+/g, '-')
+ .replace(/(^-|-$)/g, '');
+}
+
+function update_watch_user() {
+ var Dom = YAHOO.util.Dom;
+ if (Dom.get('watch_user_auto').checked) {
+ Dom.addClass('watch_user', 'bz_default_hidden');
+
+ var component = Dom.get('component').value;
+ var watch = '';
+ if (component == '') {
+ watch = '(no component name)';
+ }
+ else {
+ watch = sanitise_name(component) +
+ '@' + sanitise_name('[% product.name FILTER js %]') + '.bugs';
+ }
+ Dom.get('watch_user_suggestion').innerHTML = ' : <b>' + watch + '</b>';
+ Dom.get('watch_user').value = watch;
+ }
+ else {
+ Dom.removeClass('watch_user', 'bz_default_hidden');
+ Dom.get('watch_user_suggestion').innerHTML = '';
+ if (Dom.get('watch_user').value == '(no component name)')
+ Dom.get('watch_user').value = '';
+ }
+}
+
+YAHOO.util.Event.onDOMReady(function() {
+ if (document.getElementById('watch_user_auto')) {
+ YAHOO.util.Event.addListener('component', 'keyup', update_watch_user);
+ YAHOO.util.Event.addListener('watch_user_auto', 'click', update_watch_user);
+ update_watch_user();
+ }
+});
+</script>
diff --git a/extensions/ComponentWatching/template/en/default/hook/global/messages-component_updated_fields.html.tmpl b/extensions/ComponentWatching/template/en/default/hook/global/messages-component_updated_fields.html.tmpl
index 38c7e8c8a..f9554b072 100644
--- a/extensions/ComponentWatching/template/en/default/hook/global/messages-component_updated_fields.html.tmpl
+++ b/extensions/ComponentWatching/template/en/default/hook/global/messages-component_updated_fields.html.tmpl
@@ -13,3 +13,6 @@
<li>Watch User deleted</li>
[% END %]
[% END %]
+[% IF changes.watch_user_login.defined %]
+ <li>Watch User renamed to '[% comp.watch_user.login FILTER html %]'</li>
+[% END %]