[bugzilla-gnome-org-extensions] initial import



commit b1e36e036067363a877112499dad420b274617e1
Author: Olav Vitters <olav vitters nl>
Date:   Wed Feb 29 10:42:12 2012 +0100

    initial import

 Config.pm                                          |   33 +++
 Extension.pm                                       |  251 ++++++++++++++++++++
 lib/Util.pm                                        |   34 +++
 template/en/default/developers/README              |   16 ++
 template/en/default/hook/README                    |    5 +
 template/en/default/hook/global/user-end.html.tmpl |   30 +++
 web/README                                         |    7 +
 7 files changed, 376 insertions(+), 0 deletions(-)
---
diff --git a/Config.pm b/Config.pm
new file mode 100644
index 0000000..46bad3f
--- /dev/null
+++ b/Config.pm
@@ -0,0 +1,33 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Developers Bugzilla Extension.
+#
+# The Initial Developer of the Original Code is Olav Vitters
+# Portions created by the Initial Developer are Copyright (C) 2011 the
+# Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#   Olav Vitters <olav vitters nl>
+
+package Bugzilla::Extension::Developers;
+use strict;
+
+use constant NAME => 'Developers';
+
+use constant REQUIRED_MODULES => [
+];
+
+use constant OPTIONAL_MODULES => [
+];
+
+__PACKAGE__->NAME;
diff --git a/Extension.pm b/Extension.pm
new file mode 100644
index 0000000..da6763a
--- /dev/null
+++ b/Extension.pm
@@ -0,0 +1,251 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Developers Bugzilla Extension.
+#
+# The Initial Developer of the Original Code is Olav Vitters
+# Portions created by the Initial Developer are Copyright (C) 2011 the
+# Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#   Olav Vitters <olav vitters nl>
+
+package Bugzilla::Extension::Developers;
+use strict;
+use base qw(Bugzilla::Extension);
+
+# This code for this is in ./extensions/Developers/lib/Util.pm
+use Bugzilla::Extension::Developers::Util;
+use Bugzilla::Constants;
+
+our $VERSION = '0.01';
+
+BEGIN {
+        *Bugzilla::Product::developers = \&developers;
+        *Bugzilla::User::is_developer = \&is_developer;
+}
+
+# See the documentation of Bugzilla::Hook ("perldoc Bugzilla::Hook" 
+# in the bugzilla directory) for a list of all available hooks.
+sub install_update_db {
+    my ($self, $args) = @_;
+
+    _migrate_gnome_developers();
+}
+
+sub _migrate_gnome_developers {
+    my $dbh = Bugzilla->dbh;
+
+    # Create the global developer group if it doesn't yet exist
+    my $dev_group = Bugzilla::Group->new({ name => 'developers' });
+    return 1 if $dev_group;
+
+    $dev_group = Bugzilla::Group->create({
+        name        => 'developers',
+        description => 'All developers in every product',
+        isbuggroup  => 1,
+        isactive    => 1,
+    });
+
+    # Create product specific groups:
+    foreach my $product (Bugzilla::Product->get_all) {
+        my $group = Bugzilla::Group->new(
+            { name => $product->name . '_developers' });
+        if (!$group) {
+            # Create the group
+            $group = Bugzilla::Group->create({
+                name        => $product->name . '_developers',
+                description => $product->name . ' Developers',
+                isbuggroup  => 1,
+                isactive    => 1,
+            });
+
+            $dbh->do('INSERT INTO group_control_map
+                      (group_id, product_id, entry, membercontrol,
+                       othercontrol, canedit, editcomponents)
+                      VALUES (?, ?, 0, ?, ?, 0, 1)',
+                      undef, ($group->id, $product->id, CONTROLMAPSHOWN, 
+                              CONTROLMAPSHOWN));
+
+            $dbh->do('INSERT INTO group_group_map
+                      (member_id, grantor_id, grant_type)
+                      VALUES (?, ?, ?)',
+                      undef, ($group->id, $dev_group->id, GROUP_MEMBERSHIP));
+
+            # XXX - check&add differently
+            $dbh->do('INSERT INTO group_control_map
+                      (group_id, product_id, entry, membercontrol,
+                       othercontrol, canedit, editcomponents)
+                      VALUES (?, ?, 0, ?, ?, 0, 0)',
+                      undef, ($dev_group, $product->id, CONTROLMAPSHOWN, 
+                              CONTROLMAPSHOWN));
+
+        }
+    }
+}
+
+sub object_end_of_create {
+    my ($self, $args) = @_;
+
+    my $class  = $args->{'class'};
+    my $object = $args->{'object'};
+
+    if ($class->isa('Bugzilla::Product')) {
+        _create_developer($object);
+    }
+}
+
+sub _create_developer {
+    my $self = shift;
+
+    # For every product in Bugzilla, create a group named like 
+    # "<product_name>_developers". 
+    # Every developer in the product should be made a member of this group.
+    my $new_group = Bugzilla::Group->create({
+        name        => $self->{'name'} . '_developers',
+        description => $self->{'name'} . ' Developers',
+        isactive    => 1,
+        isbuggroup  => 1,
+    });
+ 
+    # The "<product name>_developers" group should be set to
+    # "MemberControl: Shown, OtherControl: N/A" in the product's group controls.
+    #
+    # The "<product name>_developers" group should also be given editcomponents 
+    # for the product.
+    my $dbh = Bugzilla->dbh;
+    $dbh->do('INSERT INTO group_control_map
+              (group_id, product_id, entry, membercontrol,
+               othercontrol, canedit, editcomponents)
+              VALUES (?, ?, 0, ?, ?, 0, 1)',
+              undef, ($new_group->id, $self->id, CONTROLMAPSHOWN, CONTROLMAPSHOWN));
+
+    # The group should be able to bless itself.
+    $dbh->do('INSERT INTO group_group_map (grantor_id, member_id, grant_type)
+                   VALUES (?,?,?)',
+              undef, $new_group->id, $new_group->id, GROUP_BLESS);
+
+    # The new <product_name>_developers groups should be automatically
+    # made a member of the global developers group
+    my $dev_group = Bugzilla::Group->new({ name => 'developers' });
+    if (!$dev_group) {
+        $dev_group = Bugzilla::Group->create({
+            name        => 'developers',
+            description => 'Developers',
+            isbuggroup  => 1,
+            isactive    => 1,
+        });
+    }
+
+    $dbh->do('INSERT INTO group_group_map
+              (member_id, grantor_id, grant_type)
+              VALUES (?, ?, ?)',
+             undef, ($new_group->id, $dev_group->id, GROUP_MEMBERSHIP));
+}
+
+
+sub object_before_delete {
+    my ($self, $args) = @_;
+
+    my $object = $args->{'object'};
+
+    # Note that this is a made-up class, for this example.
+    if ($object->isa('Bugzilla::Product')) {
+        my $id = $object->id;
+        _delete_developer($object);
+    } 
+}
+
+sub _delete_developer {
+    my $self = shift;
+
+    my $dbh = Bugzilla->dbh;
+
+    # Delete this product's developer group and its members
+    my $group = Bugzilla::Group->new({ name => $self->name . '_developers' });
+    if ($group) {
+        $dbh->do('DELETE FROM user_group_map WHERE group_id = ?',
+                  undef, $group->id);
+        $dbh->do('DELETE FROM group_group_map 
+                  WHERE grantor_id = ? OR member_id = ?',
+                  undef, ($group->id, $group->id));
+        $dbh->do('DELETE FROM bug_group_map WHERE group_id = ?',
+                  undef, $group->id);
+        $dbh->do('DELETE FROM group_control_map WHERE group_id = ?',
+                  undef, $group->id);
+        $dbh->do('DELETE FROM groups WHERE id = ?',
+                  undef, $group->id);
+    }
+}
+
+sub object_end_of_update {
+    my ($self, $args) = @_;
+
+    my ($object, $old_object, $changes) =
+        @$args{qw(object old_object changes)};
+
+    # Note that this is a made-up class, for this example.
+    if ($object->isa('Bugzilla::Product')) {
+        if (defined $changes->{'name'}) {
+            my ($old, $new) = @{ $changes->{'name'} };
+            _rename_developer($object, $old_object, $changes);
+        }
+    }
+}
+
+sub _rename_developer {
+    my ($self, $old_self, $changes) = @_;
+
+    my $developer_group = new Bugzilla::Group(
+        { name => $old_self->name . "_developers" });
+    my $new_group = new Bugzilla::Group(
+        { name => $self->name . '_developers' });
+    if ($developer_group && !$new_group) {
+        $developer_group->set_name($self->name . "_developers");
+        $developer_group->set_description($self->name . " Developers");
+        $developer_group->update();
+    }
+}
+
+
+sub developers {
+    my ($self) = @_;
+
+    if (!defined $self->{'developers'}) {
+        $self->{'developers'} = [];
+
+        my $group = Bugzilla::Group->new({ name => $self->name . '_developers' });
+        $self->{developers} = $group ? $group->members_non_inherited : [];
+    }
+
+    return $self->{'developers'};
+}
+
+
+sub is_developer {
+    my ($self, $product) = @_;
+
+    if ($product) {
+        # Given the only use of this is being passed bug.product_obj,
+        # at the moment the performance of this should be fine.
+        my $devs = $product->developers;
+        my $is_dev = grep { $_->id == $self->id } @$devs;
+        return $is_dev ? 1 : 0;
+    }
+    else {
+        return $self->in_group("developers") ? 1 : 0;
+    }
+
+    return 0; 
+}
+
+__PACKAGE__->NAME;
diff --git a/lib/Util.pm b/lib/Util.pm
new file mode 100644
index 0000000..77e879d
--- /dev/null
+++ b/lib/Util.pm
@@ -0,0 +1,34 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Developers Bugzilla Extension.
+#
+# The Initial Developer of the Original Code is YOUR NAME
+# Portions created by the Initial Developer are Copyright (C) 2011 the
+# Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#   YOUR NAME <YOUR EMAIL ADDRESS>
+
+package Bugzilla::Extension::Developers::Util;
+use strict;
+use base qw(Exporter);
+our @EXPORT = qw(
+    
+);
+
+# This file can be loaded by your extension via 
+# "use Bugzilla::Extension::Developers::Util". You can put functions
+# used by your extension in here. (Make sure you also list them in
+# @EXPORT.)
+
+1;
\ No newline at end of file
diff --git a/template/en/default/developers/README b/template/en/default/developers/README
new file mode 100644
index 0000000..636ecf9
--- /dev/null
+++ b/template/en/default/developers/README
@@ -0,0 +1,16 @@
+Normal templates go in this directory. You can load them in your
+code like this:
+
+use Bugzilla::Error;
+my $template = Bugzilla->template;
+$template->process('developers/some-template.html.tmpl')
+  or ThrowTemplateError($template->error());
+
+That would be how to load a file called some-template.html.tmpl that
+was in this directory.
+
+Note that you have to be careful that the full path of your template
+never conflicts with a template that exists in Bugzilla or in 
+another extension, or your template might override that template. That's why
+we created this directory called 'developers' for you, so you
+can put your templates in here to help avoid conflicts.
\ No newline at end of file
diff --git a/template/en/default/hook/README b/template/en/default/hook/README
new file mode 100644
index 0000000..e6c4add
--- /dev/null
+++ b/template/en/default/hook/README
@@ -0,0 +1,5 @@
+Template hooks go in this directory. Template hooks are called in normal
+Bugzilla templates like [% Hook.process('some-hook') %].
+More information about them can be found in the documentation of 
+Bugzilla::Extension. (Do "perldoc Bugzilla::Extension" from the main
+Bugzilla directory to see that documentation.)
\ No newline at end of file
diff --git a/template/en/default/hook/global/user-end.html.tmpl 
b/template/en/default/hook/global/user-end.html.tmpl
new file mode 100644
index 0000000..cefe88d
--- /dev/null
+++ b/template/en/default/hook/global/user-end.html.tmpl
@@ -0,0 +1,30 @@
+[%# The contents of this file are subject to the Mozilla Public
+  # License Version 1.1 (the "License"); you may not use this file
+  # except in compliance with the License. You may obtain a copy of
+  # the License at http://www.mozilla.org/MPL/
+  #
+  # Software distributed under the License is distributed on an "AS
+  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+  # implied. See the License for the specific language governing
+  # rights and limitations under the License.
+  #
+  # The Original Code is the Bugzilla Bug Tracking System.
+  #
+  # The Initial Developer of the Original Code is Everything Solved, Inc.
+  # Portions created by the Initial Developer are Copyright (C) 2010
+  # the Initial Developer. All Rights Reserved.
+  #
+  # Contributor(s): 
+  #   Max Kanat-Alexander <mkanat bugzilla org>
+  #%]
+
+[% IF comment.defined && bug.defined && mode.defined && mode == 'edit' %]
+  [% IF comment.author.id == bug.reporter.id %]
+    <span class="comment_reporter_tag">[reporter]</span>
+  [% END %]
+  [% IF comment.author.is_developer %]
+    <span class="comment_developer_tag">
+      [[% IF comment.author.is_developer(bug.product_obj) %][% bug.product FILTER html %]&nbsp;[% END 
%]developer]
+    </span>
+  [% END %]
+[% END %]
diff --git a/web/README b/web/README
new file mode 100644
index 0000000..2345641
--- /dev/null
+++ b/web/README
@@ -0,0 +1,7 @@
+Web-accessible files, like JavaScript, CSS, and images go in this
+directory. You can reference them directly in your HTML. For example,
+if you have a file called "style.css" and your extension is called
+"Foo", you would put it in "extensions/Foo/web/style.css", and then
+you could link to it in HTML like:
+
+<link href="extensions/Foo/web/style.css" rel="stylesheet" type="text/css">
\ No newline at end of file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]