From: Andrew Chilton Date: Sun, 31 Jul 2011 03:55:50 +0000 (+1200) Subject: Issue:1 - Can now obfuscate email addresses X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=86e3aaf385a51161d27117a3d16f32b8738cd57f;p=cil.git Issue:1 - Can now obfuscate email addresses --- diff --git a/lib/CIL.pm b/lib/CIL.pm index ee82ff2..c75d17b 100644 --- a/lib/CIL.pm +++ b/lib/CIL.pm @@ -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} ); diff --git a/lib/CIL/Attachment.pm b/lib/CIL/Attachment.pm index ee2a73a..9ab83f0 100644 --- a/lib/CIL/Attachment.pm +++ b/lib/CIL/Attachment.pm @@ -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; } diff --git a/lib/CIL/Base.pm b/lib/CIL/Base.pm index 34fba60..ecd134e 100644 --- a/lib/CIL/Base.pm +++ b/lib/CIL/Base.pm @@ -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 { diff --git a/lib/CIL/Command/Add.pm b/lib/CIL/Command/Add.pm index 76b1785..dd6004f 100644 --- a/lib/CIL/Command/Add.pm +++ b/lib/CIL/Command/Add.pm @@ -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 ) { diff --git a/lib/CIL/Command/Attach.pm b/lib/CIL/Command/Attach.pm index f114614..493aa27 100644 --- a/lib/CIL/Command/Attach.pm +++ b/lib/CIL/Command/Attach.pm @@ -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"); } diff --git a/lib/CIL/Command/Comment.pm b/lib/CIL/Command/Comment.pm index 0942982..c50a9e9 100644 --- a/lib/CIL/Command/Comment.pm +++ b/lib/CIL/Command/Comment.pm @@ -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 diff --git a/lib/CIL/Command/Edit.pm b/lib/CIL/Command/Edit.pm index 2f7a7e0..65aa10e 100644 --- a/lib/CIL/Command/Edit.pm +++ b/lib/CIL/Command/Edit.pm @@ -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) ) { diff --git a/lib/CIL/Comment.pm b/lib/CIL/Comment.pm index 5fa572b..9a89db6 100644 --- a/lib/CIL/Comment.pm +++ b/lib/CIL/Comment.pm @@ -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; } diff --git a/lib/CIL/Issue.pm b/lib/CIL/Issue.pm index 883516d..5fd233a 100644 --- a/lib/CIL/Issue.pm +++ b/lib/CIL/Issue.pm @@ -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; } diff --git a/lib/CIL/Utils.pm b/lib/CIL/Utils.pm index a76f513..d553509 100644 --- a/lib/CIL/Utils.pm +++ b/lib/CIL/Utils.pm @@ -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);