[Bps-public-commit] rtx-calendar branch add-callback-to-modify-query created. 1.04-5-g31c9731

BPS Git Server git at git.bestpractical.com
Fri Sep 30 17:01:25 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rtx-calendar".

The branch, add-callback-to-modify-query has been created
        at  31c973185b2910323ad05a7fb23d5d5983da1c2f (commit)

- Log -----------------------------------------------------------------
commit 31c973185b2910323ad05a7fb23d5d5983da1c2f
Author: Brad Embree <brad at bestpractical.com>
Date:   Fri Sep 30 10:01:07 2022 -0700

    Update MANIFEST

diff --git a/MANIFEST b/MANIFEST
index f88506c..53bf616 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,6 +1,8 @@
 CHANGES
 etc/tabs_privileged_callback.patch
+html/Callbacks/RTx-Calendar/Elements/MyCalendar/BeforeFindTickets
 html/Callbacks/RTx-Calendar/Elements/Tabs/Privileged
+html/Callbacks/RTx-Calendar/Search/Calendar.html/BeforeFindTickets
 html/Elements/CalendarEvent
 html/Elements/MyCalendar
 html/Search/Calendar.html

commit b3e6e3c9821ee0d77fec0020121c9d8808b9f594
Author: Brad Embree <brad at bestpractical.com>
Date:   Fri Sep 30 09:59:52 2022 -0700

    Add Help text for __UserGroups__

diff --git a/html/Search/Calendar.html b/html/Search/Calendar.html
index 9c5e71e..2c2abc7 100644
--- a/html/Search/Calendar.html
+++ b/html/Search/Calendar.html
@@ -170,6 +170,15 @@ You can change the default Query of Calendar.html and MyCalendar
 portlet by saving a query with the name <code>calendar</code> in the [_1].
 </&>
 </p>
+<p>
+You can use the special value __UserGroups__ in your searches to indicate it
+should match any of the user's groups.
+</p>
+<p>
+For example if you have a search with RequestorGroup = '__UserGroups__' then
+the calendar will show all tickets where any one of the user's groups matches
+one of the Requestor's groups.
+</p>
 
 </&>
 

commit b34a0334c3900de5aa7b545430a3c73330fe025a
Author: Brad Embree <brad at bestpractical.com>
Date:   Fri Sep 30 09:46:49 2022 -0700

    Add BeforeFindTickets callbacks

diff --git a/html/Callbacks/RTx-Calendar/Elements/MyCalendar/BeforeFindTickets b/html/Callbacks/RTx-Calendar/Elements/MyCalendar/BeforeFindTickets
new file mode 100644
index 0000000..2c47742
--- /dev/null
+++ b/html/Callbacks/RTx-Calendar/Elements/MyCalendar/BeforeFindTickets
@@ -0,0 +1,8 @@
+<%ARGS>
+$QueryRef
+$FormatRef
+</%ARGS>
+<%INIT>
+RTx::Calendar->ParseQuery($QueryRef);
+RTx::Calendar->ParseFormat($FormatRef);
+</%INIT>
diff --git a/html/Callbacks/RTx-Calendar/Search/Calendar.html/BeforeFindTickets b/html/Callbacks/RTx-Calendar/Search/Calendar.html/BeforeFindTickets
new file mode 100644
index 0000000..2c47742
--- /dev/null
+++ b/html/Callbacks/RTx-Calendar/Search/Calendar.html/BeforeFindTickets
@@ -0,0 +1,8 @@
+<%ARGS>
+$QueryRef
+$FormatRef
+</%ARGS>
+<%INIT>
+RTx::Calendar->ParseQuery($QueryRef);
+RTx::Calendar->ParseFormat($FormatRef);
+</%INIT>

commit 630b43b8298df4b47e617c089abdc36b9f179b08
Author: Brad Embree <brad at bestpractical.com>
Date:   Fri Sep 30 09:45:55 2022 -0700

    Add ParseQuery and ParseFormat class methods

diff --git a/lib/RTx/Calendar.pm b/lib/RTx/Calendar.pm
index edb7507..ae1c70e 100644
--- a/lib/RTx/Calendar.pm
+++ b/lib/RTx/Calendar.pm
@@ -131,6 +131,38 @@ sub SearchDefaultCalendar {
     }
 }
 
+sub ParseQuery {
+    my $class = shift;
+    my $QueryRef = shift;
+
+    my $CurrentUser = $HTML::Mason::Commands::session{'CurrentUser'};
+
+    # expand __UserGroups__ to string of ORs for each of the user's group's id
+    while ( $$QueryRef =~ / *(\w+) *= *'__UserGroups__'/ ) {
+        my $group_field = $1;
+        my @group_ids;
+        my $Groups = RT::Groups->new($CurrentUser);
+        $Groups->LimitToUserDefinedGroups;
+        $Groups->WithCurrentUser;
+        while ( my $group = $Groups->Next ) {
+            push @group_ids, $group->Id;
+        }
+        if ( @group_ids ) {
+            my $sql_string = '( '
+                . join( ' OR ', map { "( $group_field = '$_' )" } @group_ids )
+                . ' )';
+            $$QueryRef =~ s/$group_field *= *'__UserGroups__'/$sql_string/g;
+        } else {
+            $$QueryRef =~ s/$group_field *= *'__UserGroups__'/$group_field = '0'/g;
+        }
+    }
+}
+
+sub ParseFormat {
+    my $class = shift;
+    my $FormatRef = shift;
+}
+
 1;
 
 __END__

commit 404070310da96cc4ba6b4020dd36ca75694828ba
Author: Brad Embree <brad at bestpractical.com>
Date:   Fri Sep 30 09:42:16 2022 -0700

    Add a callback to BeforeFindTickets

diff --git a/html/Elements/MyCalendar b/html/Elements/MyCalendar
index 068dd84..175c7e9 100644
--- a/html/Elements/MyCalendar
+++ b/html/Elements/MyCalendar
@@ -78,7 +78,7 @@ my %DateTypes = map { $_ => 1 } @Dates;
 
 $Query .= RTx::Calendar::DatesClauses(\@Dates, $begin->strftime("%F"), $end->strftime("%F"));
 
-# print STDERR $Query, "\n";
+$m->callback( CallbackName => 'BeforeFindTickets', ARGSRef => \%ARGS, QueryRef => \$Query, FormatRef => \$Format );
 
 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $Query, \@Dates);
 
diff --git a/html/Search/Calendar.html b/html/Search/Calendar.html
index 5eceb0c..9c5e71e 100644
--- a/html/Search/Calendar.html
+++ b/html/Search/Calendar.html
@@ -250,7 +250,7 @@ my %DateTypes = map { $_ => 1 } @Dates;
 
 $TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->strftime("%F"));
 
-# print STDERR ("-" x 30), "\n", $TempQuery, "\n";
+$m->callback( CallbackName => 'BeforeFindTickets', ARGSRef => \%ARGS, QueryRef => \$TempQuery, FormatRef => \$TempFormat );
 
 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));
 

-----------------------------------------------------------------------


hooks/post-receive
-- 
rtx-calendar


More information about the Bps-public-commit mailing list