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

BPS Git Server git at git.bestpractical.com
Mon Oct 3 23:02:48 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  1257e1a832d46bd1c62f58b4aaeb95c7dbf9b705 (commit)

- Log -----------------------------------------------------------------
commit 1257e1a832d46bd1c62f58b4aaeb95c7dbf9b705
Author: Brad Embree <brad at bestpractical.com>
Date:   Mon Oct 3 16:01:08 2022 -0700

    Prep for version 1.05

diff --git a/CHANGES b/CHANGES
index 8acc2f4..120ca8c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,11 @@
+1.05 2022-10-03
+ - Add a class method to parse the calendar query and replace __UserGroups__
+   with all the user's groups. This lets you limit the tickets on the calendar
+   to the current user's groups with a single saved search instead of a search
+   per user or per group.
+ - also add a callback named BeforeFindTickets so user could modify the query or
+   format of the calendar search
+
 1.04 2022-09-21
  - Include user's groups and system when looking for calendar saved search
 
diff --git a/META.yml b/META.yml
index d975b94..d7cb0e0 100644
--- a/META.yml
+++ b/META.yml
@@ -26,6 +26,6 @@ requires:
   perl: 5.10.1
 resources:
   license: http://opensource.org/licenses/gpl-license.php
-version: '1.04'
+version: '1.05'
 x_module_install_rtx_version: '0.43'
 x_requires_rt: 4.2.0
diff --git a/lib/RTx/Calendar.pm b/lib/RTx/Calendar.pm
index bce9a47..53424fe 100644
--- a/lib/RTx/Calendar.pm
+++ b/lib/RTx/Calendar.pm
@@ -4,7 +4,7 @@ use strict;
 use DateTime;
 use DateTime::Set;
 
-our $VERSION = "1.04";
+our $VERSION = "1.05";
 
 RT->AddStyleSheets('calendar.css');
 

commit bed5346d7710b6e8485ba764751c68173596ddc5
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 a60aa81..799ed82 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 5787eda9062223727faa951422564c3ec15b14a9
Author: Brad Embree <brad at bestpractical.com>
Date:   Mon Oct 3 15:46:55 2022 -0700

    Add calls to ParseQuery

diff --git a/html/Elements/MyCalendar b/html/Elements/MyCalendar
index 175c7e9..8f02346 100644
--- a/html/Elements/MyCalendar
+++ b/html/Elements/MyCalendar
@@ -80,6 +80,8 @@ $Query .= RTx::Calendar::DatesClauses(\@Dates, $begin->strftime("%F"), $end->str
 
 $m->callback( CallbackName => 'BeforeFindTickets', ARGSRef => \%ARGS, QueryRef => \$Query, FormatRef => \$Format );
 
+RTx::Calendar->ParseQuery(\$Query);
+
 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $Query, \@Dates);
 
 </%INIT>
diff --git a/html/Search/Calendar.html b/html/Search/Calendar.html
index 9c5e71e..a60aa81 100644
--- a/html/Search/Calendar.html
+++ b/html/Search/Calendar.html
@@ -252,6 +252,8 @@ $TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->
 
 $m->callback( CallbackName => 'BeforeFindTickets', ARGSRef => \%ARGS, QueryRef => \$TempQuery, FormatRef => \$TempFormat );
 
+RTx::Calendar->ParseQuery(\$TempQuery);
+
 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));
 
 </%INIT>

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

    Add ParseQuery class method

diff --git a/lib/RTx/Calendar.pm b/lib/RTx/Calendar.pm
index edb7507..bce9a47 100644
--- a/lib/RTx/Calendar.pm
+++ b/lib/RTx/Calendar.pm
@@ -131,6 +131,38 @@ sub SearchDefaultCalendar {
     }
 }
 
+#
+# Takes ref to query string and parses the query to expand special tokens:
+#
+#   __UserGroups__ => string of ORs for each of the user's group's id
+#
+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;
+        }
+    }
+}
+
 1;
 
 __END__

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

    Add a callback named BeforeFindTickets
    
    This callback will allow a user to modify the calendar query and/or format as
    desired before the search is run.

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