You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by cu...@apache.org on 2019/06/02 23:08:13 UTC

[whimsy] branch mail_ldap_notification created (now 5e74b3a)

This is an automated email from the ASF dual-hosted git repository.

curcuru pushed a change to branch mail_ldap_notification
in repository https://gitbox.apache.org/repos/asf/whimsy.git.


      at 5e74b3a  Encapsulate sending mail from roster tool

This branch includes the following new commits:

     new 5e74b3a  Encapsulate sending mail from roster tool

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



Re: [whimsy] 01/01: Encapsulate sending mail from roster tool

Posted by sebb <se...@gmail.com>.
On Mon, 3 Jun 2019 at 02:16, Sam Ruby <ru...@intertwingly.net> wrote:
>
> On Sun, Jun 2, 2019 at 8:01 PM Shane Curcuru <as...@shanecurcuru.org> wrote:
> >
> > sebb wrote on 2019-6-2 7:30PM EDT:
> > > On Mon, 3 Jun 2019 at 00:08, <cu...@apache.org> wrote:
> > >>
> > >> This is an automated email from the ASF dual-hosted git repository.
> > >>
> > >> curcuru pushed a commit to branch mail_ldap_notification
> > >> in repository https://gitbox.apache.org/repos/asf/whimsy.git
> > >>
> > >> commit 5e74b3aac094e105af73c3c49ec09f49e33d9e31
> > >> Author: Shane Curcuru <as...@shanecurcuru.org>
> > >> AuthorDate: Sun Jun 2 19:08:05 2019 -0400
> > >>
> > >>     Encapsulate sending mail from roster tool
> > >>
> > >>     In progress; currently gives "ReferenceError: Can't find variable: __FILE__"
> > >
> > > I think that is because the file is converted to Javascript (*.js.rb)
> > > __FILE__ is a Ruby construct.
> > >
> > > Is it intended that Javascript should send the email directly from the
> > > browser client?
> >
> > It's simply encapsulating the same duplicated code in various
> > roster/views/actions/*.json.rb files, like appgroup/committee/etc.
> > While they each process the to/cc and such differently, the core
> > mail.new.... deliver etc. code is the same, and it felt useful to put
> > them all in the same place.
> >
> > I also hope to use ERB templates for the mail bodies, so it's easier to
> > maintain, and add an X-mailer header.
> >
> > But obviously I'm not understanding some of the limitations the ruby2js
> > steps put on the code (like not being able to def func(keyword: arg) )
> > yet.
>
> What's not obvious is that the contents of the views directory
> *except* for the actions subdirectory are run on the client.  If there
> is a desire to factor out code from actions, it needs to be placed
> outside of the views directory and required by main.rb.

Also the actions directory contains files named *.json.rb whereas the
others are *.js.rb and *.html.rb

> [just catching up on the mailing list after talking Shane through this
> via slack]
>
> > --
> >
> > - Shane
> >   Whimsy PMC
> >   The Apache Software Foundation
>
> - Sam Ruby

Re: [whimsy] 01/01: Encapsulate sending mail from roster tool

Posted by Sam Ruby <ru...@intertwingly.net>.
On Sun, Jun 2, 2019 at 8:01 PM Shane Curcuru <as...@shanecurcuru.org> wrote:
>
> sebb wrote on 2019-6-2 7:30PM EDT:
> > On Mon, 3 Jun 2019 at 00:08, <cu...@apache.org> wrote:
> >>
> >> This is an automated email from the ASF dual-hosted git repository.
> >>
> >> curcuru pushed a commit to branch mail_ldap_notification
> >> in repository https://gitbox.apache.org/repos/asf/whimsy.git
> >>
> >> commit 5e74b3aac094e105af73c3c49ec09f49e33d9e31
> >> Author: Shane Curcuru <as...@shanecurcuru.org>
> >> AuthorDate: Sun Jun 2 19:08:05 2019 -0400
> >>
> >>     Encapsulate sending mail from roster tool
> >>
> >>     In progress; currently gives "ReferenceError: Can't find variable: __FILE__"
> >
> > I think that is because the file is converted to Javascript (*.js.rb)
> > __FILE__ is a Ruby construct.
> >
> > Is it intended that Javascript should send the email directly from the
> > browser client?
>
> It's simply encapsulating the same duplicated code in various
> roster/views/actions/*.json.rb files, like appgroup/committee/etc.
> While they each process the to/cc and such differently, the core
> mail.new.... deliver etc. code is the same, and it felt useful to put
> them all in the same place.
>
> I also hope to use ERB templates for the mail bodies, so it's easier to
> maintain, and add an X-mailer header.
>
> But obviously I'm not understanding some of the limitations the ruby2js
> steps put on the code (like not being able to def func(keyword: arg) )
> yet.

What's not obvious is that the contents of the views directory
*except* for the actions subdirectory are run on the client.  If there
is a desire to factor out code from actions, it needs to be placed
outside of the views directory and required by main.rb.

[just catching up on the mailing list after talking Shane through this
via slack]

> --
>
> - Shane
>   Whimsy PMC
>   The Apache Software Foundation

- Sam Ruby

Re: [whimsy] 01/01: Encapsulate sending mail from roster tool

Posted by Shane Curcuru <as...@shanecurcuru.org>.
sebb wrote on 2019-6-2 7:30PM EDT:
> On Mon, 3 Jun 2019 at 00:08, <cu...@apache.org> wrote:
>>
>> This is an automated email from the ASF dual-hosted git repository.
>>
>> curcuru pushed a commit to branch mail_ldap_notification
>> in repository https://gitbox.apache.org/repos/asf/whimsy.git
>>
>> commit 5e74b3aac094e105af73c3c49ec09f49e33d9e31
>> Author: Shane Curcuru <as...@shanecurcuru.org>
>> AuthorDate: Sun Jun 2 19:08:05 2019 -0400
>>
>>     Encapsulate sending mail from roster tool
>>
>>     In progress; currently gives "ReferenceError: Can't find variable: __FILE__"
> 
> I think that is because the file is converted to Javascript (*.js.rb)
> __FILE__ is a Ruby construct.
> 
> Is it intended that Javascript should send the email directly from the
> browser client?

It's simply encapsulating the same duplicated code in various
roster/views/actions/*.json.rb files, like appgroup/committee/etc.
While they each process the to/cc and such differently, the core
mail.new.... deliver etc. code is the same, and it felt useful to put
them all in the same place.

I also hope to use ERB templates for the mail bodies, so it's easier to
maintain, and add an X-mailer header.

But obviously I'm not understanding some of the limitations the ruby2js
steps put on the code (like not being able to def func(keyword: arg) )
yet.

-- 

- Shane
  Whimsy PMC
  The Apache Software Foundation

Re: [whimsy] 01/01: Encapsulate sending mail from roster tool

Posted by sebb <se...@gmail.com>.
On Mon, 3 Jun 2019 at 00:08, <cu...@apache.org> wrote:
>
> This is an automated email from the ASF dual-hosted git repository.
>
> curcuru pushed a commit to branch mail_ldap_notification
> in repository https://gitbox.apache.org/repos/asf/whimsy.git
>
> commit 5e74b3aac094e105af73c3c49ec09f49e33d9e31
> Author: Shane Curcuru <as...@shanecurcuru.org>
> AuthorDate: Sun Jun 2 19:08:05 2019 -0400
>
>     Encapsulate sending mail from roster tool
>
>     In progress; currently gives "ReferenceError: Can't find variable: __FILE__"

I think that is because the file is converted to Javascript (*.js.rb)
__FILE__ is a Ruby construct.

Is it intended that Javascript should send the email directly from the
browser client?

That seems odd.

S.
> ---
>  www/roster/views/utils.js.rb | 49 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 49 insertions(+)
>
> diff --git a/www/roster/views/utils.js.rb b/www/roster/views/utils.js.rb
> index 1d68c68..2ec2e94 100644
> --- a/www/roster/views/utils.js.rb
> +++ b/www/roster/views/utils.js.rb
> @@ -1,3 +1,4 @@
> +# Utility functions used throughout roster tool
>  class Utils
>
>    # Common processing to handle a response that is expected to be JSON
> @@ -23,4 +24,52 @@ class Utils
>        end
>      end
>    end
> +
> +  # Deliver an LDAP notification email, e.g. pmc/ppmc/group/etc. changes
> +  # Uses creates and mail.deliver! using a template for body
> +  # Includes X-headers to mark as Whimsy email
> +  # DEBUGGING: options: true to prevent actual mail sending
> +  def self.mail_ldap_notification(
> +    from,
> +    to,
> +    cc,
> +    bcc,
> +    subject,
> +    template,
> +    data, # Hash for ERB
> +    options
> +  )
> +    # TODO how should this method report problems?
> +    raise ArgumentError, "From must not be nil or blank" if from.nil? || from == ''
> +    raise ArgumentError, "To or CC must not be nil" if to.nil? && cc.nil?
> +    raise ArgumentError, "Subject must not be nil or blank" if subject.nil? || subject == ''
> +    raise ArgumentError, "Template must not be nil or blank" if template.nil? || template == ''
> +
> +    path = File.expand_path("../../templates/#{template}", __FILE__.untaint)
> +    file = File.join(path, template)
> +    puts "-> #{path} #{template} #{file}"
> +    tmplt = File.read(file.untaint).untaint
> +    mail = Mail.new do
> +      from from
> +      to to
> +      cc cc
> +      bcc bcc
> +      subject subject
> +      b = binding # Bind the passed in data hash to send to ERB
> +      data.each do |key, val|
> +        b.local_variable_set(key.to_sym, val)
> +      end
> +      body ERB.new(tmplt).result(b)
> +    end
> +
> +    # Header for root@ mail filters, per request infra
> +    mail.header['X-For-Root'] = 'yes'
> +    # Header to denote automated mail from whimsy
> +    mail.header['X-Mailer'] = 'whimsy/www/roster/utils(0.1)'
> +
> +    # Deliver email
> +    mail.delivery_method :test if options # TODO DEBUGGING don't actually send mail, just log it
> +    mail.deliver!
> +    return mail
> +  end
>  end
>

[whimsy] 01/01: Encapsulate sending mail from roster tool

Posted by cu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

curcuru pushed a commit to branch mail_ldap_notification
in repository https://gitbox.apache.org/repos/asf/whimsy.git

commit 5e74b3aac094e105af73c3c49ec09f49e33d9e31
Author: Shane Curcuru <as...@shanecurcuru.org>
AuthorDate: Sun Jun 2 19:08:05 2019 -0400

    Encapsulate sending mail from roster tool
    
    In progress; currently gives "ReferenceError: Can't find variable: __FILE__"
---
 www/roster/views/utils.js.rb | 49 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/www/roster/views/utils.js.rb b/www/roster/views/utils.js.rb
index 1d68c68..2ec2e94 100644
--- a/www/roster/views/utils.js.rb
+++ b/www/roster/views/utils.js.rb
@@ -1,3 +1,4 @@
+# Utility functions used throughout roster tool
 class Utils
 
   # Common processing to handle a response that is expected to be JSON
@@ -23,4 +24,52 @@ class Utils
       end
     end
   end
+  
+  # Deliver an LDAP notification email, e.g. pmc/ppmc/group/etc. changes
+  # Uses creates and mail.deliver! using a template for body
+  # Includes X-headers to mark as Whimsy email
+  # DEBUGGING: options: true to prevent actual mail sending
+  def self.mail_ldap_notification(
+    from,
+    to,
+    cc,
+    bcc,
+    subject,
+    template,
+    data, # Hash for ERB
+    options
+  )
+    # TODO how should this method report problems?
+    raise ArgumentError, "From must not be nil or blank" if from.nil? || from == ''
+    raise ArgumentError, "To or CC must not be nil" if to.nil? && cc.nil?
+    raise ArgumentError, "Subject must not be nil or blank" if subject.nil? || subject == ''
+    raise ArgumentError, "Template must not be nil or blank" if template.nil? || template == ''
+    
+    path = File.expand_path("../../templates/#{template}", __FILE__.untaint)
+    file = File.join(path, template)
+    puts "-> #{path} #{template} #{file}"
+    tmplt = File.read(file.untaint).untaint
+    mail = Mail.new do
+      from from
+      to to
+      cc cc
+      bcc bcc
+      subject subject
+      b = binding # Bind the passed in data hash to send to ERB
+      data.each do |key, val|
+        b.local_variable_set(key.to_sym, val)
+      end
+      body ERB.new(tmplt).result(b) 
+    end
+
+    # Header for root@ mail filters, per request infra
+    mail.header['X-For-Root'] = 'yes'
+    # Header to denote automated mail from whimsy
+    mail.header['X-Mailer'] = 'whimsy/www/roster/utils(0.1)'
+
+    # Deliver email
+    mail.delivery_method :test if options # TODO DEBUGGING don't actually send mail, just log it
+    mail.deliver!
+    return mail
+  end
 end