[Bps-public-commit] rtx-calendar branch search-groups-and-system-for-calendar-search created. 1.03-1-ga649d30

BPS Git Server git at git.bestpractical.com
Wed Sep 21 03:42:55 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, search-groups-and-system-for-calendar-search has been created
        at  a649d30efa6dde581f76aee4b673da0e5f3e3266 (commit)

- Log -----------------------------------------------------------------
commit a649d30efa6dde581f76aee4b673da0e5f3e3266
Author: Brad Embree <brad at bestpractical.com>
Date:   Fri Sep 16 07:57:46 2022 -0700

    Include user's groups and system when looking for calendar saved search
    
    Also formatted the code with perltidy

diff --git a/lib/RTx/Calendar.pm b/lib/RTx/Calendar.pm
index 300912d..4c51583 100644
--- a/lib/RTx/Calendar.pm
+++ b/lib/RTx/Calendar.pm
@@ -9,10 +9,11 @@ our $VERSION = "1.03";
 RT->AddStyleSheets('calendar.css');
 
 sub FirstDay {
-    my ($year, $month, $matchday) = @_;
-    my $set = DateTime::Set->from_recurrence(
-	next => sub { $_[0]->truncate( to => 'day' )->subtract( days => 1 ) }
-    );
+    my ( $year, $month, $matchday ) = @_;
+    my $set
+        = DateTime::Set->from_recurrence(
+        next => sub { $_[0]->truncate( to => 'day' )->subtract( days => 1 ) }
+        );
 
     my $day = DateTime->new( year => $year, month => $month );
 
@@ -22,10 +23,9 @@ sub FirstDay {
 }
 
 sub LastDay {
-    my ($year, $month, $matchday) = @_;
+    my ( $year, $month, $matchday ) = @_;
     my $set = DateTime::Set->from_recurrence(
-	next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
-    );
+        next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) } );
 
     my $day = DateTime->last_day_of_month( year => $year, month => $month );
 
@@ -36,30 +36,30 @@ sub LastDay {
 # we can't use RT::Date::Date because it uses gmtime
 # and we need localtime
 sub LocalDate {
-  my $ts = shift;
-  my ($d,$m,$y) = (localtime($ts))[3..5];
-  sprintf "%4d-%02d-%02d", ($y + 1900), ++$m, $d;
+    my $ts = shift;
+    my ( $d, $m, $y ) = ( localtime($ts) )[ 3 .. 5 ];
+    sprintf "%4d-%02d-%02d", ( $y + 1900 ), ++$m, $d;
 }
 
 sub DatesClauses {
-    my ($Dates, $begin, $end) = @_;
+    my ( $Dates, $begin, $end ) = @_;
 
     my $clauses = "";
 
     my @DateClauses = map {
-	"($_ >= '" . $begin . " 00:00:00' AND $_ <= '" . $end . " 23:59:59')"
+        "($_ >= '" . $begin . " 00:00:00' AND $_ <= '" . $end . " 23:59:59')"
     } @$Dates;
-    $clauses  .= " AND " . " ( " . join(" OR ", @DateClauses) . " ) "
-	if @DateClauses;
+    $clauses .= " AND " . " ( " . join( " OR ", @DateClauses ) . " ) "
+        if @DateClauses;
 
-    return $clauses
+    return $clauses;
 }
 
 sub FindTickets {
-    my ($CurrentUser, $Query, $Dates, $begin, $end) = @_;
+    my ( $CurrentUser, $Query, $Dates, $begin, $end ) = @_;
 
-    $Query .= DatesClauses($Dates, $begin, $end)
-	if $begin and $end;
+    $Query .= DatesClauses( $Dates, $begin, $end )
+        if $begin and $end;
 
     my $Tickets = RT::Tickets->new($CurrentUser);
     $Tickets->FromSQL($Query);
@@ -67,16 +67,20 @@ sub FindTickets {
     my %Tickets;
     my %AlreadySeen;
 
-    while ( my $Ticket = $Tickets->Next()) {
+    while ( my $Ticket = $Tickets->Next() ) {
+
+        # How to find the LastContacted date ?
+        for my $Date (@$Dates) {
+            my $DateObj = $Date . "Obj";
+            push @{ $Tickets{ LocalDate( $Ticket->$DateObj->Unix ) } },
+                $Ticket
 
-	# How to find the LastContacted date ?
-	for my $Date (@$Dates) {
-	    my $DateObj = $Date . "Obj";
-	    push @{ $Tickets{ LocalDate($Ticket->$DateObj->Unix) } }, $Ticket
-		# if reminder, check it's refering to a ticket
-		unless ($Ticket->Type eq 'reminder' and not $Ticket->RefersTo->First)
-		    or $AlreadySeen{  LocalDate($Ticket->$DateObj->Unix) }{ $Ticket }++;
-	}
+                # if reminder, check it's refering to a ticket
+                unless ( $Ticket->Type eq 'reminder'
+                and not $Ticket->RefersTo->First )
+                or $AlreadySeen{ LocalDate( $Ticket->$DateObj->Unix ) }
+                {$Ticket}++;
+        }
     }
     return %Tickets;
 }
@@ -88,18 +92,42 @@ sub SearchDefaultCalendar {
     my $CurrentUser = shift;
     my $Description = "calendar";
 
-    # I'm quite sure the loop isn't usefull but...
-    my @Objects = $CurrentUser->UserObj;
-    for my $object (@Objects) {
-	next unless ref($object) eq 'RT::User' && $object->id == $CurrentUser->Id;
-	my @searches = $object->Attributes->Named('SavedSearch');
-	for my $search (@searches) {
-	    next if ($search->SubValue('SearchType')
-			 && $search->SubValue('SearchType') ne 'Ticket');
-
-	    return $search
-		if "calendar" eq $search->Description;
-	}
+    my $UserObj  = $CurrentUser->UserObj;
+    my @searches = $UserObj->Attributes->Named('SavedSearch');
+    for my $search (@searches) {
+        next
+            if ( $search->SubValue('SearchType')
+            && $search->SubValue('SearchType') ne 'Ticket' );
+
+        return $search
+            if "calendar" eq $search->Description;
+    }
+
+    # search through user's groups as well
+    my $Groups = RT::Groups->new($CurrentUser);
+    $Groups->LimitToUserDefinedGroups;
+    $Groups->WithCurrentUser;
+    while ( my $group = $Groups->Next ) {
+        @searches = $group->Attributes->Named('SavedSearch');
+        for my $search (@searches) {
+            next
+                if ( $search->SubValue('SearchType')
+                && $search->SubValue('SearchType') ne 'Ticket' );
+
+            return $search
+                if "calendar" eq $search->Description;
+        }
+    }
+
+    # search thru system saved searches
+    @searches = $RT::System->Attributes->Named('SavedSearch');
+    for my $search (@searches) {
+        next
+            if ( $search->SubValue('SearchType')
+            && $search->SubValue('SearchType') ne 'Ticket' );
+
+        return $search
+            if "calendar" eq $search->Description;
     }
 }
 

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


hooks/post-receive
-- 
rtx-calendar


More information about the Bps-public-commit mailing list