madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r20517: LJSUP-10102: User don't receive notifica...

Committer: sbelyaev
LJSUP-10102: User don't receive notification when user is removed from community
U   trunk/cgi-bin/LJ/DelayedEntry.pm
U   trunk/cgi-bin/LJ/Widget/EntryForm.pm
U   trunk/htdocs/community/members.bml
U   trunk/htdocs/community/settings.bml
Modified: trunk/cgi-bin/LJ/DelayedEntry.pm
===================================================================
--- trunk/cgi-bin/LJ/DelayedEntry.pm	2011-11-09 09:47:52 UTC (rev 20516)
+++ trunk/cgi-bin/LJ/DelayedEntry.pm	2011-11-10 02:14:45 UTC (rev 20517)
@@ -870,11 +870,26 @@
     my $dbcr = LJ::get_cluster_def_reader($journal)
         or die "get cluster for journal failed";
 
-    return $dbcr->selectcol_arrayref("SELECT delayedid " .
-                                     "FROM delayedlog2 WHERE journalid=$journalid AND posterid = $userid ".
-                                     "LIMIT 1");    
+    my ($delayeds) =  $dbcr->selectcol_arrayref("SELECT delayedid " .
+                                              "FROM delayedlog2 WHERE journalid=$journalid AND posterid = $userid ".
+                                              "LIMIT 1");    
+    return @$delayeds;
 }
 
+sub get_usersids_with_delated_entry {
+    my ($journalu) = @_;
+
+    __assert($journalu);
+
+    my $journalid = $journalu->userid;
+    my $dbcr = LJ::get_cluster_def_reader($journalu) 
+        or die "get cluster for journal failed";
+
+    return $dbcr->selectcol_arrayref(  "SELECT posterid " .
+                                       "FROM delayedlog2 ".
+                                       "WHERE journalid = $journalid GROUP BY posterid" );
+}
+
 sub get_entries_count {
     my ( $class, $journal, $skip, $elements_to_show, $userid ) = @_;
     __assert($journal, "no journal");
@@ -885,7 +900,7 @@
     unless ($userid) {
         my $remote = LJ::get_remote();
         return undef unless $remote;
-        $userid = $remote->userid ;
+        $userid = $remote->userid;
 
         return undef unless __delayed_entry_can_see( $journal,
                                                      $remote );

Modified: trunk/cgi-bin/LJ/Widget/EntryForm.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/EntryForm.pm	2011-11-09 09:47:52 UTC (rev 20516)
+++ trunk/cgi-bin/LJ/Widget/EntryForm.pm	2011-11-10 02:14:45 UTC (rev 20517)
@@ -429,11 +429,11 @@
         my $usejournal = $opts->{'usejournal'};
         if ($usejournal) {
             my $posterid = $remote->userid;
-            my $ownerid = LJ::load_user($usejournal)->userid;
+            my $journalu = LJ::load_user($usejournal);
+            my $ownerid = $journalu->userid;
             my $dbh = LJ::get_db_writer();
-            $can_edit_date = !!($dbh->selectrow_array("SELECT COUNT(*) FROM reluser ".
-                                                     "WHERE userid=$ownerid AND targetid=$posterid ".
-                                                     "AND type IN ('A','M','N')")) || 0;
+            $can_edit_date = LJ::DelayedEntry::can_post_to($journalu, $remote);
+
             $out .= "<li id='usejournal_single' class='pkg'>\n";
             $out .= "<label for='usejournal' class='title'>" .
                 BML::ml('entryform.postto') . "</label>\n";

Modified: trunk/htdocs/community/members.bml
===================================================================
--- trunk/htdocs/community/members.bml	2011-11-09 09:47:52 UTC (rev 20516)
+++ trunk/htdocs/community/members.bml	2011-11-10 02:14:45 UTC (rev 20517)
@@ -306,12 +306,6 @@
              return $print_with_ad->($ret);
         }
 
-        # delete members
-        if (%{$delete{'member'}}) {
-            # TAG:FR:bml_comm_members:del_members
-            LJ::remove_friend($cid, [ keys %{$delete{'member'}} ]);
-        }
-
         # create a closure to send a notification email to a user if they are
         # added or removed from being a maintainer
         my $sendmail = sub {
@@ -372,6 +366,53 @@
             }
         };
 
+        # get all the users who were removed
+        my $changedusers = LJ::load_userids(keys %{$delete{'member'}});
+        # delete members
+        if (%{$delete{'post'}}) {
+            # TAG:FR:bml_comm_members:del_members
+            for my $uid (keys %{$delete{'member'} || {} }) {
+                my $delu = $changedusers->{$uid};
+
+                next unless $delu;
+                next unless LJ::DelayedEntry::entries_exists($c, $delu);
+                next if LJ::DelayedEntry::can_post_to($c, $delu);
+
+                my $mailusername = $delu->{user};
+                my $mailusercname = $c->{name};
+                my $mailclink = LJ::journal_base($c, ['community']);
+            
+                my $lang = $delu->prop('browselang') || $LJ::DEFAULT_LANG;
+                my $html = LJ::Lang::get_text($lang, 'community.members.delayed.remove.email_html', undef, {
+                                     sitenameshort   => $LJ::SITENAMESHORT,
+                                     user            => $mailusername,
+                                     usercname       => $mailusercname,
+                                     mailclink       => "href='$mailclink'",
+                                     remote          => $remote->{user},
+                                     sitename        => $LJ::SITENAME,
+                                     siteroot        => $LJ::SITEROOT,
+                                });
+
+                my $plain = LJ::Lang::get_text($lang, 'community.members.delayed.remove.email_plain', undef, {
+                                    sitenameshort   => $LJ::SITENAMESHORT,
+                                    user            => $mailusername,
+                                    usercname       => $mailusercname,
+                                    mailclink       => $mailclink,
+                                    remote          => $remote->{user},
+                                    sitename        => $LJ::SITENAME,
+                                    siteroot        => $LJ::SITEROOT,
+                                });
+
+
+                my $subject = LJ::Lang::get_text($lang, 'community.members.delayed.remove.email_subject', undef,
+                                { mailusercname => $mailusercname }
+                                );
+
+                $sendmail->($delu, $html, $plain, $subject); 
+            } 
+            LJ::remove_friend($cid, [ keys %{$delete{'member'}} ]);
+        }
+
         # get all the maintainers who were removed
         my $changedmaintainers = LJ::load_userids(keys %{$delete{admin}}, keys %{$add{admin}});
 
@@ -398,10 +439,6 @@
                             siteroot        => $LJ::SITEROOT,
                         });
     
-            if (LJ::DelayedEntry::entries_exists($c, $remote)) {
-                $html .=  LJ::Lang::get_text($lang, 'community.members.maintainer.remove.delayed.email_html', undef);
-            }
-
             my $plain = LJ::Lang::get_text($lang, 'community.members.maintainer.remove.email_plain', undef, {
                             sitenameshort   => $LJ::SITENAMESHORT,
                             user            => $mailusername,
@@ -412,14 +449,12 @@
                             siteroot        => $LJ::SITEROOT,
                         });
 
-            if (LJ::DelayedEntry::entries_exists($c, $remote)) {
-                $plain .=  LJ::Lang::get_text($lang, 'community.members.maintainer.remove.delayed.email_plain', undef);
             }
 
             my $subject = LJ::Lang::get_text($lang, 'community.members.maintainer.remove.email_subject', undef,
                             { mailusercname => $mailusercname }
                             );
-                $sendmail->($delmaintu, $html, $plain, $subject);
+            $sendmail->($delmaintu, $html, $plain, $subject);
         }
 
         # delete other rel edges

Modified: trunk/htdocs/community/settings.bml
===================================================================
--- trunk/htdocs/community/settings.bml	2011-11-09 09:47:52 UTC (rev 20516)
+++ trunk/htdocs/community/settings.bml	2011-11-10 02:14:45 UTC (rev 20517)
@@ -113,6 +113,101 @@
             my $qpostlevel = $POST{postlevel};
             $qpostlevel = "select" unless $qpostlevel =~ /^(?:anybody|members|select)$/;
 
+            my $sendmail = sub {
+                my ($targetu, $html, $plain, $subject) = @_;
+                return unless $targetu;
+
+                my $fromname = $remote->username;
+
+                #todo: check if user wants to receive emails?
+                if ($targetu->email_raw) {
+                    # send an email to this user:
+                    # send an email with both plain and html content
+                    my $msg = '';
+                    my $encoding = $targetu->{'mailencoding'} ?
+                                        $LJ::CACHE_ENCODINGS{$targetu->{'mailencoding'}} :
+                                        "UTF-8";
+                    if ($targetu->{opt_htmlemail} eq 'Y') {
+                        $msg =  new MIME::Lite ( 'From'    => "\"$LJ::SITENAME\" <$LJ::BOGUS_EMAIL>",
+                                                 'To'      => $targetu->email_raw,
+                                                 'Subject' => $subject,
+                                                 'Type'    => 'multipart/alternative',
+                                               );
+
+                        # add the plaintext version
+                        my $plainpart = $msg->attach( 'Type'     => 'TEXT',
+                                                      'Data'     => $plain,
+                                                      'Encoding' => 'quoted-printable',
+                                                    );
+
+                        $plainpart->attr("content-type.charset" => $encoding)
+                            if $LJ::UNICODE;
+
+                        # add the html version
+                        my $htmlpart = $msg->attach( 'Type'     => 'text/html',
+                                                     'Data'     => $html,
+                                                     'Encoding' => 'quoted-printable'
+                                                   );
+
+                        $htmlpart->attr("content-type.charset" => $encoding)
+                            if $LJ::UNICODE;
+
+                    } else {
+                        # no html version, do simple email
+                        $msg = new MIME::Lite ( 'From'    => "\"$LJ::SITENAME\" <$LJ::BOGUS_EMAIL>",
+                                                'To'      => $targetu->email_raw,
+                                                'Subject' => $subject,
+                                                'Type'    => 'text/plain',
+                                                'Data'    => $plain
+                                              );
+
+                        $msg->attr("content-type.charset" => $encoding);
+                    }
+
+                    LJ::send_mail($msg);
+                }
+            };
+
+            my $delayed_users_ids = LJ::DelayedEntry::get_usersids_with_delated_entry($cu);
+            foreach my $userid (@$delayed_users_ids) {
+                my $du = LJ::want_user($userid);
+               
+                next unless $du;
+                next if LJ::DelayedEntry::can_post_to($cu, $du);
+    
+                my $mailusername = $du->username;
+                my $mailusercname = $cu->username;
+                my $mailclink = LJ::journal_base($cu, ['community']);
+
+                my $lang = $du->prop('browselang') || $LJ::DEFAULT_LANG;
+                my $html = LJ::Lang::get_text($lang, 'community.members.delayed.remove.email_html', undef, {
+                                     sitenameshort   => $LJ::SITENAMESHORT,
+                                     user            => $mailusername,
+                                     usercname       => $mailusercname,
+                                     mailclink       => "href='$mailclink'",
+                                     remote          => $remote->username,
+                                     sitename        => $LJ::SITENAME,
+                                     siteroot        => $LJ::SITEROOT,
+                                });
+
+                my $plain = LJ::Lang::get_text($lang, 'community.members.delayed.remove.email_plain', undef, {
+                                    sitenameshort   => $LJ::SITENAMESHORT,
+                                    user            => $mailusername,
+                                    usercname       => $mailusercname,
+                                    mailclink       => $mailclink,
+                                    remote          => $remote->username,
+                                    sitename        => $LJ::SITENAME,
+                                    siteroot        => $LJ::SITEROOT,
+                                });
+
+
+                my $subject = LJ::Lang::get_text($lang, 'community.members.delayed.remove.email_subject', undef,
+                                { mailusercname => $mailusercname }
+                                );
+    
+                $sendmail->($du, $html, $plain, $subject);
+            }
+
             # postlevel and nonmember_posting are a single setting in the UI, but separate options in the backend
             # split them out so we can save them properly
             my $nonmember_posting = 0;

Tags: bml, livejournal, madeon, pm, sbelyaev
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments