]> git.mjollnir.org Git - cil.git/commitdiff
Issue:1 - Can now obfuscate email addresses
authorAndrew Chilton <andychilton@gmail.com>
Sun, 31 Jul 2011 03:55:50 +0000 (15:55 +1200)
committerAndrew Chilton <andychilton@gmail.com>
Sun, 31 Jul 2011 03:55:50 +0000 (15:55 +1200)
lib/CIL.pm
lib/CIL/Attachment.pm
lib/CIL/Base.pm
lib/CIL/Command/Add.pm
lib/CIL/Command/Attach.pm
lib/CIL/Command/Comment.pm
lib/CIL/Command/Edit.pm
lib/CIL/Comment.pm
lib/CIL/Issue.pm
lib/CIL/Utils.pm

index ee82ff206e3bc70be75147a197fb941de6424f57..c75d17bbce1ad59c44b8865999207cce9c4b74bb 100644 (file)
@@ -43,6 +43,7 @@ __PACKAGE__->mk_accessors(qw(
     LabelStrict LabelAllowed
     DefaultNewStatus
     UseGit
+    MungeEmail
     UserName UserEmail
     AutoAssignSelf
     git hook
@@ -55,6 +56,7 @@ my $defaults = {
     LabelStrict      => 0,        # whether to complain if a label is invalid
     DefaultNewStatus => 'New',    # What Status to use for new issues by default
     UseGit           => 0,        # don't do anything with Git
+    MungeEmail       => 0,        # don't munge email by default
 };
 
 my @config_hashes = qw(StatusOpen StatusClosed LabelAllowed);
@@ -279,6 +281,7 @@ sub read_config_file {
     # set each config item
     $self->IssueDir( $self->BaseDir() . q{/} . $cfg->{IssueDir} );
     $self->UseGit( $cfg->{UseGit} );
+    $self->MungeEmail( $cfg->{MungeEmail} );
 
     # Status info
     $self->StatusStrict( $cfg->{StatusStrict} );
index ee2a73aff553667199263f352dcd92d17836546b..9ab83f0ffdef8076374fdd5e87c3dc9292433c57 100644 (file)
@@ -38,7 +38,7 @@ my @FIELDS = ( qw(Issue Filename Size CreatedBy Inserted Updated File) );
 ## ----------------------------------------------------------------------------
 
 sub new {
-    my ($proto, $name) = @_;
+    my ($proto, $cil, $name) = @_;
 
     croak 'please provide an attachment name'
         unless defined $name;
@@ -61,6 +61,9 @@ sub new {
 
     $self->set_inserted_now;
 
+    # save the reference to cil itself
+    $self->cil( $cil );
+
     return $self;
 }
 
index 34fba603b1b696e7a20f3cf1f900068c5ffdfcdf..ecd134e364ecc8b6c9479da192bcaa359f1afcd8 100644 (file)
@@ -28,7 +28,16 @@ use DateTime;
 use CIL::Utils;
 
 use base qw(Class::Accessor);
-__PACKAGE__->mk_accessors(qw(CreatedBy Inserted Updated));
+__PACKAGE__->mk_accessors(qw(cil Inserted Updated));
+
+sub CreatedBy {
+    my ($self, $value) = @_;
+
+    if ( defined $value ) {
+        $self->{data}{CreatedBy} = $self->cil->MungeEmail ? CIL::Utils->munge_email($value) : $value;
+    }
+    return $self->{data}{CreatedBy};
+}
 
 ## ----------------------------------------------------------------------------
 
@@ -43,12 +52,12 @@ sub new_from_name {
         unless $cil->file_exists($filename);
 
     my $data = $cil->parse_cil_file($filename, $class->last_field);
-    my $issue = $class->new_from_data( $name, $data );
+    my $issue = $class->new_from_data( $cil, $name, $data );
     return $issue;
 }
 
 sub new_from_data {
-    my ($class, $name, $data) = @_;
+    my ($class, $cil, $name, $data) = @_;
 
     croak 'please provide an issue name'
         unless defined $name;
@@ -56,7 +65,7 @@ sub new_from_data {
     # ToDo: check we have all the other correct fields
 
     # create the issue
-    my $self = $class->new( $name );
+    my $self = $class->new( $cil, $name );
 
     my $fields = $class->fields();
     my $array_fields = $class->array_fields();
@@ -80,13 +89,13 @@ sub new_from_data {
 }
 
 sub new_from_fh {
-    my ($class, $name, $fh) = @_;
+    my ($class, $cil, $name, $fh) = @_;
 
     croak 'please provide name'
         unless defined $name;
 
     my $data = CIL::Utils->parse_from_fh( $fh, $class->last_field );
-    return $class->new_from_data( $name, $data );
+    return $class->new_from_data( $cil, $name, $data );
 }
 
 sub set_data {
index 76b178500ceb51fe1fa9105f405197e37136509f..dd6004fe718a94fb2acafaf7bada2d27c9417f24 100644 (file)
@@ -37,7 +37,8 @@ sub run {
 
     my $user = CIL::Utils->user($cil);
 
-    my $issue = CIL::Issue->new('tmpname');
+    # set up a default issue for now
+    my $issue = CIL::Issue->new( $cil, 'tmpname' );
     $issue->Summary( join ' ', @argv );
     $issue->Status($cil->DefaultNewStatus);
     $issue->CreatedBy( $user );
@@ -45,6 +46,7 @@ sub run {
         if ( $args->{mine} or $cil->AutoAssignSelf );
     $issue->Description("Description ...");
 
+    # now read in the file until the issue is valid
     $issue = CIL::Utils->add_issue_loop($cil, undef, $issue);
 
     if ( $cil->UseGit ) {
index f1146147bea24b9d4a0d509609b634a98176ae53..493aa272bf8f516e977af31989651951946da9b7 100644 (file)
@@ -57,7 +57,7 @@ EOF
     CIL::Utils->ensure_interactive();
     my $fh = CIL::Utils->solicit( $add_attachment_text );
 
-    my $attachment = CIL::Attachment->new_from_fh( 'tmp', $fh );
+    my $attachment = CIL::Attachment->new_from_fh( $cil, 'tmp', $fh );
     unless ( defined $attachment ) {
         $cil->fatal("could not create new attachment");
     }
index 094298246c2a5b532311901fb0979493eee69d01..c50a9e932ea9d6fba82bdb80f9bd8ac53d45a498 100644 (file)
@@ -38,12 +38,12 @@ sub run {
     CIL::Utils->ensure_interactive();
 
     # create the new comment
-    my $comment = CIL::Comment->new('tmpname');
+    my $comment = CIL::Comment->new( $cil, 'tmpname' );
     $comment->Issue( $issue->name );
     $comment->CreatedBy( CIL::Utils->user($cil) );
     $comment->Description("Description ...");
 
-    $comment = CIL::Utils->add_comment_loop($cil, undef, $issue, $comment);
+    $comment = CIL::Utils->add_comment_loop( $cil, undef, $issue, $comment );
 
     if ( $cil->UseGit ) {
         # if we want to add or commit this comment
index 2f7a7e0aa2d84cc845acb67c87d10df1257d2f11..65aa10ec0a52ee7d2eb813834c603c16b29c91b8 100644 (file)
@@ -47,7 +47,7 @@ sub run {
     while ( $edit eq $y ) {
         # read in the new issue text
         my $fh = CIL::Utils->solicit( $issue->as_output );
-        $issue = CIL::Issue->new_from_fh( $issue->name, $fh );
+        $issue = CIL::Issue->new_from_fh( $cil, $issue->name, $fh );
 
         # check if the issue is valid
         if ( $issue->is_valid($cil) ) {
index 5fa572b1e9cfbf2ffac9856f5398eb4a63d88368..9a89db6e08b6f660659b74557d542f0fa25aa4c3 100644 (file)
@@ -35,7 +35,7 @@ my @FIELDS = ( qw(Issue CreatedBy Inserted Updated Description) );
 ## ----------------------------------------------------------------------------
 
 sub new {
-    my ($proto, $name) = @_;
+    my ($proto, $cil, $name) = @_;
 
     croak 'please provide a comment name'
         unless defined $name;
@@ -56,6 +56,9 @@ sub new {
 
     $self->set_inserted_now;
 
+    # save the reference to cil itself
+    $self->cil( $cil );
+
     return $self;
 }
 
index 883516d9221f1d65602ea74cacc213aa5a7e1039..5fd233aa0e7599ba4253760210c794ab85d06cfc 100644 (file)
@@ -32,7 +32,7 @@ use Date::Simple;
 use base qw(CIL::Base);
 
 # fields specific to Issue
-__PACKAGE__->mk_accessors(qw(Summary Status AssignedTo DueDate DependsOn Precedes Label Comment Attachment Description));
+__PACKAGE__->mk_accessors(qw(Summary Status DueDate DependsOn Precedes Label Comment Attachment Description));
 
 my @FIELDS = ( qw(Summary Status CreatedBy AssignedTo DueDate DependsOn Precedes Label Comment Attachment Inserted Updated Description) );
 my $cfg = {
@@ -45,10 +45,20 @@ my $cfg = {
     },
 };
 
+sub AssignedTo {
+    my ($self, $value) = @_;
+
+    if ( defined $value ) {
+        $self->{data}{AssignedTo} = $self->cil->MungeEmail ? CIL::Utils->munge_email($value) : $value;
+    }
+
+    return $self->{data}{AssignedTo};
+}
+
 ## ----------------------------------------------------------------------------
 
 sub new {
-    my ($proto, $name) = @_;
+    my ($proto, $cil, $name) = @_;
 
     croak 'please provide an issue name'
         unless defined $name;
@@ -77,6 +87,9 @@ sub new {
 
     $self->set_inserted_now;
 
+    # save the reference to cil itself
+    $self->cil( $cil );
+
     return $self;
 }
 
index a76f513d38f2e40853d7823a08734e6c3bafd042..d55350983f547445a61ec61c85bbe3a52a10b5e7 100644 (file)
@@ -200,7 +200,7 @@ sub add_issue_loop {
     while ( $edit eq $y ) {
         # read in the new issue text
         my $fh = $class->solicit( $issue->as_output );
-        $issue = CIL::Issue->new_from_fh( 'tmp', $fh );
+        $issue = CIL::Issue->new_from_fh( $cil, 'tmp', $fh );
 
         # check if the issue is valid
         if ( $issue->is_valid($cil) ) {
@@ -218,6 +218,12 @@ sub add_issue_loop {
     # we've got the issue, so let's name it
     my $unique_str = time . $issue->Inserted . $issue->Summary . $issue->Description;
     $issue->set_name( substr(md5_hex($unique_str), 0, 8) );
+
+    # set these so that munging takes place
+    $issue->CreatedBy( $issue->CreatedBy() );
+    $issue->AssignedTo( $issue->AssignedTo() );
+
+    # save out to disk
     $issue->save($cil);
 
     # should probably be run from with $cil
@@ -237,7 +243,7 @@ sub add_comment_loop {
     while ( $edit eq $y ) {
         # read in the new comment text
         my $fh = CIL::Utils->solicit( $comment->as_output );
-        $comment = CIL::Comment->new_from_fh( 'tmp', $fh );
+        $comment = CIL::Comment->new_from_fh( $cil, 'tmp', $fh );
 
         # check if the comment is valid
         if ( $comment->is_valid($cil) ) {
@@ -256,6 +262,9 @@ sub add_comment_loop {
     my $unique_str = time . $comment->Inserted . $issue->Description;
     $comment->set_name( substr(md5_hex($unique_str), 0, 8) );
 
+    # set these so that munging takes place
+    $comment->CreatedBy( $issue->CreatedBy() );
+
     # finally, save it
     $comment->save($cil);
 
@@ -283,7 +292,7 @@ sub load_issue_fuzzy {
     }
 
     my $issue_name = $issues->[0]->{name};
-    my $issue = CIL::Issue->new_from_name($cil, $issue_name);
+    my $issue = CIL::Issue->new_from_name( $cil, $issue_name );
     unless ( defined $issue ) {
         $class->fatal("Couldn't load issue '$issue_name'");
     }
@@ -304,7 +313,7 @@ sub load_comment_fuzzy {
     }
 
     my $comment_name = $comments->[0]->{name};
-    my $comment = CIL::comment->new_from_name($cil, $comment_name);
+    my $comment = CIL::comment->new_from_name( $cil, $comment_name );
     unless ( defined $comment ) {
         $class->fatal("Couldn't load comment '$comment_name'");
     }
@@ -325,7 +334,7 @@ sub load_attachment_fuzzy {
     }
 
     my $attachment_name = $attachments->[0]->{name};
-    my $attachment = CIL::Attachment->new_from_name($cil, $attachment_name);
+    my $attachment = CIL::Attachment->new_from_name( $cil, $attachment_name );
     unless ( defined $attachment ) {
         $class->fatal("Couldn't load attachment '$partial_name'");
     }
@@ -515,6 +524,15 @@ sub order_issues {
     return $issues;
 }
 
+sub munge_email {
+    my ($class, $email) = @_;
+
+    $email =~ s{@}{ at }gxms;
+    $email =~ s{\.}{ dot }gxms;
+
+    return $email;
+}
+
 sub separator {
     my ($class) = @_;
     $class->msg('=' x 79);