[Rt-commit] [svn] r1418 - in RT-Journal/trunk/html/Journal: . Elements

huberth at pallas.eruditorum.org huberth at pallas.eruditorum.org
Fri Sep 3 19:27:46 EDT 2004


Author: huberth
Date: Fri Sep  3 19:27:46 2004
New Revision: 1418

Modified:
   RT-Journal/trunk/html/Journal/Article.html
   RT-Journal/trunk/html/Journal/Edit.html
   RT-Journal/trunk/html/Journal/Elements/_SetDefaults
   RT-Journal/trunk/html/Journal/Friends.html
   RT-Journal/trunk/html/Journal/Post.html
   RT-Journal/trunk/html/Journal/Show.html
Log:
 * Friends lists made workable.
 * Private/friends-only/custom-friends-locked posts now work.
 * Other minor fixes.

Modified: RT-Journal/trunk/html/Journal/Article.html
==============================================================================
--- RT-Journal/trunk/html/Journal/Article.html	(original)
+++ RT-Journal/trunk/html/Journal/Article.html	Fri Sep  3 19:27:46 2004
@@ -6,22 +6,55 @@
 my $post = RT::Ticket->new( $session{'CurrentUser'} );
 my @Actions;
 if ( $ARGS{'id'} eq 'new' ) {    # new ticket?
-    my $q = RT::Queue->new( $session{'CurrentUser'} );
-    $q->Load($RT::JournalQueue);
-    $ARGS{'Queue'}  = $q->id;
-    $ARGS{'Owner'}  = $session{'CurrentUser'}->id;
-    $ARGS{'Status'} = 'new';
-
-    my $cat = RT::CustomField->new( $session{'CurrentUser'} );
-    $cat->LoadByNameAndQueue( Queue => $q->Id, Name => 'RT::Journal-Category');
-
-    $ARGS{ 'CustomField-' . $cat->Id } = $ARGS{'Category'};
-
-    #$ARGS{'Attachments'}{'Upload'} = $ARGS{'Attach'};
-    delete $ARGS{'Attach'};
-
-    ( $post, @Actions ) = CreateTicket(%ARGS);
+    if ($ARGS{'privacy'} eq "Public") {
+	my $q = RT::Queue->new( $session{'CurrentUser'} );
+	$q->Load($RT::JournalQueue);
+	$ARGS{'Queue'}  = $q->id;
+	$ARGS{'Owner'}  = $session{'CurrentUser'}->id;
+	$ARGS{'Status'} = 'new';
+	
+	my $cat = RT::CustomField->new( $session{'CurrentUser'} );
+	$cat->LoadByNameAndQueue( Queue => $q->Id, Name => 'RT::Journal-Category');
+	
+	$ARGS{ 'CustomField-' . $cat->Id } = $ARGS{'Category'};
+	
+	#$ARGS{'Attachments'}{'Upload'} = $ARGS{'Attach'};
+	delete $ARGS{'Attach'};
+	
+	( $post, @Actions ) = CreateTicket(%ARGS);
+	$post->AddAttribute(Name => "privacy", Content => $ARGS{'privacy'});
+    } else {
+	my $q = RT::Queue->new( $session{'CurrentUser'} );
+	$q->Load($RT::PrivateJournalQueue);
+	$ARGS{'Queue'}  = $q->id;
+	$ARGS{'Owner'}  = $session{'CurrentUser'}->id;
+	$ARGS{'Status'} = 'new';
+	
+	my $cat = RT::CustomField->new( $session{'CurrentUser'} );
+	$cat->LoadByNameAndQueue( Queue => $q->Id, Name => 'RT::Journal-Category');
+	
+	$ARGS{ 'CustomField-' . $cat->Id } = $ARGS{'Category'};
+	
+	#$ARGS{'Attachments'}{'Upload'} = $ARGS{'Attach'};
+	delete $ARGS{'Attach'};
+	
+	my $userobj = RT::User->new($session{'CurrentUser'});
+	$userobj->Load($session{'CurrentUser'}->Id);
+	my @cc;
+	if ($ARGS{'privacy'} eq "Friends") {
+	    my $friendsgroup = RT::Group->new($session{'CurrentUser'});
+	    $friendsgroup->LoadPersonalGroup(Name => "friends", User => $userobj->Id);
+            $ARGS{'Cc'} = $friendsgroup->Id;
+	} elsif ($ARGS{'privacy'} =~ /^Custom-(.*)/) {
+	    my $friendsgroup = RT::Group->new($session{'CurrentUser'});
+	    $friendsgroup->LoadPersonalGroup(Name => $1, User => $userobj->Id);
+            $ARGS{'Cc'} = $friendsgroup->Id;
+	}
+	print $ARGS{'Cc'} . "<BR>";
 
+	( $post, @Actions ) = CreateTicket(%ARGS);
+	$post->AddAttribute(Name => "privacy", Content => $ARGS{'privacy'});
+    }
 }
 else {
     $post->Load($id);
@@ -29,11 +62,18 @@
         $post->Correspond( Content => $comment );
     }
 }
+my $privacy = $post->FirstAttribute("privacy");
+$privacy = $privacy->Content if ($privacy);
 </%init>
 %$m->comp( 'Elements/Tabs', Title => $post->CreatorObj->Name.": ".$post->Subject );
 
 <h1><%$post->Subject%></h1>
 (<%$post->CreatedObj->AsString%>)<br>
+% if ($privacy eq "Private") {
+<h4>[private]</h4>
+% } elsif ($privacy eq "Friends" || $privacy =~ /^Custom/) {
+<h4>[friends]</h4>
+% }
 
 <%$post->FirstCustomFieldValue('RT-Journal::Category')%>
 <br>
@@ -66,7 +106,6 @@
 % while (my $comment = $history->Next) {
 %   my $attach = $comment->Attachments;
 
-
 <%$comment->CreatorObj->Name%> (<%$comment->CreatedObj->AsString%>)<br>
 
 <%$comment->Content%>

Modified: RT-Journal/trunk/html/Journal/Edit.html
==============================================================================
--- RT-Journal/trunk/html/Journal/Edit.html	(original)
+++ RT-Journal/trunk/html/Journal/Edit.html	Fri Sep  3 19:27:46 2004
@@ -16,6 +16,17 @@
 <b>Post:</b><br>
 <textarea rows=20 cols=80 name="Content"><%$attachment->Content%></textarea>
 <br>
+<b><&|/l&>Privacy</&></b>:
+<select name="privacy">
+<option value="Public" <%$privacy eq "Public"?"SELECTED":""%>>Public</option>
+<option value="Friends" <%$privacy eq "Friends"?"SELECTED":""%>>Friends</option>
+<option value="Private" <%$privacy eq "Private"?"SELECTED":""%>>Private</option>
+% while (my $group = $allgroups->Next) {
+%     next if ($group->Name eq "friends");
+<option value=<% "Custom-" . $group->Name %> <%$privacy eq "Custom-".$group->Name?"SELECTED":""%>><% $group->Name %></option>
+% }
+</select>
+<br>
 <input type=submit value="Edit Post">
 </form>
 
@@ -36,6 +47,48 @@
         ($content_val,$content_msg) = $attachment->_Set( Field =>'Content', Value => $ARGS{'Content'});
 }
 
+my $allgroups = RT::Groups->new($session{'CurrentUser'});
+$allgroups->LimitToPersonalGroupsFor($session{'CurrentUser'}->PrincipalId);
+
+my $privacy = $ticket->FirstAttribute("privacy")->Content;
+
+if ($ARGS{'privacy'} ne $privacy) {
+    # oh joy.
+
+    my $newprivacy = $ARGS{'privacy'};
+    
+    # set privacy
+    $ticket->SetAttribute(Name => "privacy", Content => $newprivacy);
+
+    # move to correct queue (RT::Journal / RT::PrivateJournals)
+    my $newqueue = $newprivacy eq "Public" ? $RT::JournalQueue : $RT::PrivateJournalQueue;
+    $ticket->SetQueue($newqueue);
+
+    my $userobj = RT::User->new($session{'CurrentUser'});
+    $userobj->Load($session{'CurrentUser'}->Id);
+
+    # delete a watcher if necessary
+    if ($privacy eq "Friends") {
+        my $group = RT::Group->new($session{'CurrentUser'});
+	$group->LoadPersonalGroup(Name => "friends", User => $userobj->Id);
+	$ticket->DeleteWatcher(Type => "Cc", PrincipalId => $group->Id);
+    } elsif ($privacy =~ /^Custom-(.*)/) {
+        my $group = RT::Group->new($session{'CurrentUser'});
+	$group->LoadPersonalGroup(Name => $1, User => $userobj->Id);
+	$ticket->DeleteWatcher(Type => "Cc", PrincipalId => $group->Id);
+    }
+
+    # delete a watcher if necessary
+    if ($newprivacy eq "Friends") {
+        my $group = RT::Group->new($session{'CurrentUser'});
+	$group->LoadPersonalGroup(Name => "friends", User => $userobj->Id);
+	$ticket->AddWatcher(Type => "Cc", PrincipalId => $group->Id);
+    } elsif ($newprivacy =~ /^Custom-(.*)/) {
+        my $group = RT::Group->new($session{'CurrentUser'});
+	$group->LoadPersonalGroup(Name => $1, User => $userobj->Id);
+	$ticket->AddWatcher(Type => "Cc", PrincipalId => $group->Id);
+    }
+}
 
 </%INIT>
 <%ARGS>

Modified: RT-Journal/trunk/html/Journal/Elements/_SetDefaults
==============================================================================
--- RT-Journal/trunk/html/Journal/Elements/_SetDefaults	(original)
+++ RT-Journal/trunk/html/Journal/Elements/_SetDefaults	Fri Sep  3 19:27:46 2004
@@ -1,4 +1,5 @@
 <%init>
 $RT::JournalQueue ||= 'RT::Journal';
+$RT::PrivateJournalQueue ||= 'RT::PrivateJournals';
 return();
 </%init>

Modified: RT-Journal/trunk/html/Journal/Friends.html
==============================================================================
--- RT-Journal/trunk/html/Journal/Friends.html	(original)
+++ RT-Journal/trunk/html/Journal/Friends.html	Fri Sep  3 19:27:46 2004
@@ -3,9 +3,9 @@
 <form action="Friends.html" method=post>
 
 <h3>Current Friends:</h3> <i>(check box to remove)</i><br><br>
-% foreach my $friend (@friends) {
-<input type="checkbox" name="removefriend-<%$friend->Content%>">
-<% $namelookup{$friend->Content} %><br>
+% while (my $friend = $friends->Next) {
+<input type="checkbox" name="removefriend-<%$friend->Id%>">
+<% $namelookup{$friend->Id} %><br>
 % }
 
 Add Friend:
@@ -20,31 +20,43 @@
 </form>
 
 <%INIT>
-my $userobj = $session{'CurrentUser'};
-my @friends = $userobj->Attributes->Named("friend");
+my $userobj = RT::User->new($session{'CurrentUser'});
+$userobj->Load($session{'CurrentUser'}->Id);
+my $friendsgroup = RT::Group->new($session{'CurrentUser'});
+my ($id, $msg) = $friendsgroup->LoadPersonalGroup(Name => "friends", User => $userobj->Id);
+unless ($id) {
+    ($id, $msg) = $friendsgroup->CreatePersonalGroup(Name => "friends");
+    $friendsgroup->LoadPersonalGroup(Name => "friends", User => $userobj->Id);
+}
+my $friends = $friendsgroup->UserMembersObj;
+
+#my @friends = $userobj->Attributes->Named("friend");
 my @nonfriends;
 my %namelookup;
 
 my $nfs = RT::Users->new($session{'CurrentUser'});
 $nfs->LimitToPrivileged;
 
-foreach my $friend (@friends) { 
-#   print $friend->Content . "<br>";
-   if ($ARGS{'removefriend-' . $friend->Content}) {
-        $userobj->Attributes->DeleteEntry(Name    => "friend",
-	                                  Content => $friend->Content);
+while (my $friend = $friends->Next) {
+   if ($ARGS{'removefriend-' . $friend->Id}) {
+        $friendsgroup->DeleteMember($friend->Id);
    }
 }
 
 if ($ARGS{'addfriend'}) {
 #    print "adding " . $ARGS{'addfriend'} . "<br>";
-    $userobj->AddAttribute( Name => "friend", Content => $ARGS{'addfriend'} );
+    $friendsgroup->AddMember($ARGS{'addfriend'});
+#    $userobj->AddAttribute( Name => "friend", Content => $ARGS{'addfriend'} );
+}
+$friends = $friendsgroup->UserMembersObj;
+my @allfriends;
+while (my $friend = $friends->Next) {
+    push @allfriends, ($friend->Id);
 }
- at friends = $userobj->Attributes->Named("friend");
 
 while (my $nf = $nfs->Next) {
     $namelookup{$nf->Id} = $nf->Name;
-    my $match = grep {$_ == $nf->Id} map {$_->Content} @friends;
+    my $match = grep {$_ == $nf->Id} @allfriends;
     push @nonfriends, ($nf->Id) if ($match == 0);
 }
 

Modified: RT-Journal/trunk/html/Journal/Post.html
==============================================================================
--- RT-Journal/trunk/html/Journal/Post.html	(original)
+++ RT-Journal/trunk/html/Journal/Post.html	Fri Sep  3 19:27:46 2004
@@ -9,10 +9,10 @@
 
 <BR>
 <b><&|/l&>Subject</&></b>:
-<INPUT Name="Subject" SIZE=60 MAXSIZE=100 value="<%$ARGS{Subject} || ''%>"><br>
-<b><&|/l&>Category</&></b>:<& Elements/SelectCategory &><br>
-%# <&|/l&>Attach</&>: <INPUT TYPE=FILE NAME="Attach"><br>
-<&|/l&>Content</&>:<br>
+<INPUT Name="Subject" SIZE=60 MAXSIZE=150 value="<%$ARGS{Subject} || ''%>"><br><br>
+<b><&|/l&>Category</&></b>:<& Elements/SelectCategory &><br><br>
+%# <&|/l&>Attach</&>: <INPUT TYPE=FILE NAME="Attach"><br><br>
+<b><&|/l&>Post</&></b>:<br>
 
 <& /Elements/MessageBox, Default => $ARGS{Content} &>
 
@@ -23,6 +23,17 @@
 
 <BR>
 
+<b><&|/l&>Privacy</&></b>:
+<select name="privacy">
+<option value="Public">Public</option>
+<option value="Friends">Friends</option>
+<option value="Private">Private</option>
+% while (my $group = $allgroups->Next) {
+%     next if ($group->Name eq "friends");
+<option value=<% "Custom-" . $group->Name %>><% $group->Name %></option>
+% }
+</select>
+
 <& /Elements/Submit, Label => loc("Create") &>
 </FORM>
 
@@ -37,4 +48,7 @@
 my $cat = RT::CustomField->new($session{'CurrentUser'});
 $cat->LoadByNameAndQueue(Queue => $q->Id, Name => 'RT::Journal-Category');
 
+my $allgroups = RT::Groups->new($session{'CurrentUser'});
+$allgroups->LimitToPersonalGroupsFor($session{'CurrentUser'}->PrincipalId);
+
 </%INIT>

Modified: RT-Journal/trunk/html/Journal/Show.html
==============================================================================
--- RT-Journal/trunk/html/Journal/Show.html	(original)
+++ RT-Journal/trunk/html/Journal/Show.html	Fri Sep  3 19:27:46 2004
@@ -11,13 +11,20 @@
 
 % my $any = 0;
 % while (my $post = $tix->Next) {
+%     my $privacy = $post->FirstAttribute("privacy");
+%     $privacy = $privacy->Content if ($privacy);
 %     $any = 1;
 %     my $my_category = $post->FirstCustomFieldValue('RT::Journal-Category');
 <%$post->CreatedObj->AsString%><br>
 <h2><a href="Article.html?id=<%$post->id%>"><%$post->Transactions->First->Subject|| loc('Untitled')%></a>
-%     unless ($user) {
+%     unless ($user || ($who ne "friends")) {
 - [<%$post->OwnerObj->Name%>]
 %     }
+%     if ($privacy eq "Private") {
+- [private]
+%     } elsif ($privacy eq "Friends" || $privacy =~ /^Custom/) {
+- [friends]
+%     }
 </h2>
 %     my $content = $post->Transactions->First->Content;
 %     $content =~ s/^-- (.*)$//gism; # kill all signatures
@@ -31,16 +38,17 @@
 </div>
 %     my $comments = $post->Transactions;
 %     $comments->Limit(FIELD => 'Type', VALUE => 'Correspond');
+<br>
 [<a href="Article.html?id=<%$post->Id%>"><&|/l,$comments->Count&>[_1] Comments</&></a>]
 <a href="Show.html?show=<%$ARGS{'show'}%>&user=<%$user%>&category=<%$my_category%>"><%$my_category%></a>
 <hr>
 % }
 
 % if ($total >= $first + $count) {
-<a href="Show.html?show=<%$ARGS{'show'}%>&user=<%$user%>&category=<%$category%>&first=<%$first+$count%>&count=<%$count%>"><&|/l&>Next page</&></a> |
+<a href="Show.html?who=<%$ARGS{'who'}%>&user=<%$user%>&category=<%$category%>&first=<%$first+$count%>&count=<%$count%>"><&|/l&>Next page</&></a> |
 % }
 % if ($first > 1) {
-<a href="Show.html?show=<%$ARGS{'show'}%>&user=<%$user%>&category=<%$category%>&first=<%$first-$count%>&count=<%$count%>"><&|/l&>Previous page</&></a> |
+<a href="Show.html?who=<%$ARGS{'who'}%>&user=<%$user%>&category=<%$category%>&first=<%$first-$count%>&count=<%$count%>"><&|/l&>Previous page</&></a> |
 % } 
 
 % if ($any == 0) {
@@ -54,40 +62,49 @@
 <%INIT>
 my $q = RT::Queue->new($RT::SystemUser);
 $q->Load($RT::JournalQueue);
+my $pq = RT::Queue->new($RT::SystemUser);
+$pq->Load($RT::PrivateJournalQueue);
 
 my $cat = RT::CustomField->new($RT::SystemUser);
 $cat->LoadByNameAndQueue( Name => 'RT::Journal-Category', Queue => $q->Id );
 
+my $userobj = RT::User->new($session{'CurrentUser'});
+if ($user) {
+    $userobj->Load($user);
+} else {
+    $userobj->Load($session{'CurrentUser'}->Id);
+}
+
 my $tix = RT::Tickets->new( $session{'CurrentUser'} );
-$tix->LimitQueue( VALUE => $RT::JournalQueue );
-$tix->OrderBy( FIELD => 'Created', ORDER => 'DESC' );
+#$tix->LimitQueue( VALUE => $RT::JournalQueue );
+#$tix->OrderBy( FIELD => 'Created', ORDER => 'DESC' );
+
 if ($who eq "friends") {
     my $querystring = "";
     my $querybase = "Owner = ";
-    my $userobj;
-    if ($user) {
-        $userobj = RT::User->new($session{'CurrentUser'});
-        $userobj->Load($user);
-    } else {
-        $userobj = $session{'CurrentUser'};
+    my $friendsgroup = RT::Group->new($session{'CurrentUser'});
+    $friendsgroup->LoadPersonalGroup(Name => "friends", User => $userobj->Id);
+    my $friends = $friendsgroup->UserMembersObj;
+    my @friends;
+    while (my $friend = $friends->Next) {
+        push @friends, ($friend->Id);
     }
-    my @friends = $userobj->Attributes->Named("friend");
-    foreach my $friend (@friends) {
-	$querystring .= " OR " . $querybase . "'" . $friend->Content ."'";
-    }
-    $querystring =~ s/^ OR //;
-    if ($querystring eq "") {
-        # no friends.  show nothing.
+    $querystring = join(" OR ", map {"creator = '$_'"} @friends);
+
+    # if no friends, show nothing.
+    $querystring = "creator = '1' AND creator = '2'" if $querystring eq "";
+
+    $querystring .= " AND ( Queue = '" . $q->Id . "' OR Queue = '" . $pq->Id . "' )";
 
-        $querystring = "Owner = '1' AND Owner = '2'";
-    }
-    $querystring .= " AND Queue = '" . $q->Id . "'";
-#    $tix = RT::Tickets->new( $session{'CurrentUser'} );
     $tix->FromSQL($querystring);
     $tix->OrderBy( FIELD => 'Created', ORDER => 'DESC' );
 } elsif ($user) {
-    $tix->LimitOwner( VALUE => $user );
+    my $querystring = "Owner = '" . $userobj->Id . "'";
+    $querystring .= " AND ( Queue = '" . $q->Id . "' OR Queue = '" . $pq->Id . "' )";
+    $tix->FromSQL($querystring);    
+    $tix->OrderBy( FIELD => 'Created', ORDER => 'DESC' );
 }
+
 if ($category) {
     $tix->LimitCustomField(
         CUSTOMFIELD => $cat->Id,
@@ -95,8 +112,22 @@
         VALUE       => $category . "%"
     );
 }
+
 my $total = $tix->Count;
-$tix->RowsPerPage($count);
+
+my $perpage = $count;
+if ($who eq "friends") {
+    my @val = $userobj->Attributes->Named("entriesperpage-friends");
+    $perpage = $val[0] if (scalar @val);
+} elsif ($user) {
+    my @val = $userobj->Attributes->Named("entriesperpage-journal");
+    $perpage = $val[0] if (scalar @val);
+} else {
+    my @val = $userobj->Attributes->Named("entriesperpage-allposts");
+    $perpage = $val[0] if (scalar @val);
+}
+
+$tix->RowsPerPage($perpage);
 $tix->FirstRow($first);
 </%INIT>
 <%ARGS>


More information about the Rt-commit mailing list