Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
MariagraziaAlastra committed Mar 27, 2015
2 parents 75fdfe7 + 4dff1d2 commit 0c5ef02
Show file tree
Hide file tree
Showing 50 changed files with 1,215 additions and 153 deletions.
6 changes: 6 additions & 0 deletions lib/DDGC/DB/Result/InstantAnswer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ column src_api_documentation => {
is_nullable => 1,
};

# api status page
column api_status_page => {
data_type => 'text',
is_nullable => 1,
};

# favicon url, if necessary. can usually be inferred from the domain
column icon_url => {
data_type => 'text',
Expand Down
39 changes: 6 additions & 33 deletions lib/DDGC/DB/Result/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ column email => {
is_nullable => 1,
};

column email_verified => {
data_type => 'int',
is_nullable => 0,
default_value => 0,
};

column userpage => {
data_type => 'text',
is_nullable => 1,
Expand Down Expand Up @@ -447,39 +453,6 @@ sub profile_picture {
}
}

sub gravatar_to_avatar {
my ($self) = @_;
return unless $self->public;
my $gravatar_email;
return if (-f $self->avatar_filename );

if ($self->data && defined $self->data->{gravatar_email}) {
$gravatar_email = $self->data->{gravatar_email};
}

if ($self->data && defined $self->data->{userpage} && defined $self->data->{userpage}->{gravatar_email}) {
$gravatar_email = $self->data->{userpage}->{gravatar_email};
}

if ($self->userpage && defined $self->userpage->{gravatar_email}) {
$gravatar_email = $self->userpage->{gravatar_email};
}

return unless $gravatar_email;
my $md5 = md5_hex($gravatar_email);

my ($fh, $filename) = tempfile();
my $url = "http://www.gravatar.com/avatar/$md5?r=g&s=200";

unless (is_success(getstore($url, $filename))) {
carp("Unable to retrieve $url for " . $self->username);
return 0;
}

return unless $self->store_avatar($filename);
$self->generate_thumbs;
}

sub generate_thumbs {
my ($self) = @_;
my $fn = $self->username_to_filename;
Expand Down
2 changes: 1 addition & 1 deletion lib/DDGC/DuckPAN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sub add_user_distribution {
$self->log("ERROR",$user->lc_username,"is no admin, adding denied");
return 'Only admins may upload so far ('.$user->username.')';
}
unless ($user->data && $user->data->{email}) {
unless ($user->email) {
$self->log("ERROR",$user->lc_username,"has no email, adding denied");
return 'You need an email to upload ('.$user->username.')';
}
Expand Down
11 changes: 7 additions & 4 deletions lib/DDGC/Postman.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ sub _build_transport {
}

sub mail {
my ( $self, $to, $from, $subject, $body, %extra_headers ) = @_;
my ( $self, $verified, $to, $from, $subject, $body, %extra_headers ) = @_;
return unless $verified;
die __PACKAGE__."->mail needs to, from, subject, body" unless $body && $subject && $to && $from;
$subject =~ s/\n/ /g;
my $email = Email::Simple->create(
Expand All @@ -59,14 +60,16 @@ sub mail {
}

sub template_mail {
my ( $self, $to, $from, $subject, $template, $stash, %extra ) = @_;
my ( $self, $verified, $to, $from, $subject, $template, $stash, %extra ) = @_;
return unless $verified;
$stash->{email_template} = "email/".$template.".tx";
my $body = $self->ddgc->xslate->render('email/base.tx',$stash);
return $self->html_mail($to, $from, $subject, $body, %extra);
return $self->html_mail($verified, $to, $from, $subject, $body, %extra);
}

sub html_mail {
my ( $self, $to, $from, $subject, $body, %extra ) = @_;
my ( $self, $verified, $to, $from, $subject, $body, %extra ) = @_;
return unless $verified;
die __PACKAGE__."->mail needs to, from, subject, body" unless $body && $subject && $to && $from;

my @parts = defined $extra{parts}
Expand Down
2 changes: 1 addition & 1 deletion lib/DDGC/Web/Controller/Campaign/SubmitResponse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ BAD_RESPONSE_LINK
my $error = 0;
try {
$c->d->postman->template_mail(
$to, $from, $subject, 'campaign', $c->stash
1, $to, $from, $subject, 'campaign', $c->stash
);
}
catch {
Expand Down
10 changes: 6 additions & 4 deletions lib/DDGC/Web/Controller/Cronjob.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ sub notify_cycle {
$c->d->db->txn_do(sub {
my $users_id = $_->get_column('users_id');
my $user = $c->d->rs('User')->find($users_id);
if ($user->data && $user->data->{email}) {
if ($user->email && $user->email_verified) {
$c->d->as($user,sub {
$c->stash->{unsent_notifications_results} = [$user->unsent_notifications_cycle($cycle)->all];
$c->stash->{unsent_notifications_count} = scalar @{$c->stash->{unsent_notifications_results}};
unless ($skip_notify) {
try {
$c->d->postman->template_mail(
$user->data->{email},
$user->email_verified,
$user->email,
'"DuckDuckGo Community Envoy" <[email protected]>',
'[DuckDuckGo Community] '.$c->stash->{unsent_notifications_count}.' new notifications for you',
'notifications',
Expand All @@ -75,8 +76,9 @@ sub notify_cycle {
catch {
try {
$c->d->errorlog("Mailing notifications to " .
$user->data->{email} . " failed, mailing " . $c->d->config->error_email);
$user->email . " failed, mailing " . $c->d->config->error_email);
$c->d->postman->mail(
1,
$c->d->config->error_email,
'"DuckDuckGo Community Envoy" <[email protected]>',
'[DuckDuckGo Community] ERROR ON ENVOY',
Expand All @@ -86,7 +88,7 @@ sub notify_cycle {
catch {
$c->d->errorlog("Failed to mail error report about mailing " .
$c->stash->{unsent_notifications_count} . " notifications to " .
$user->data->{email});
$user->email);
};
};
}
Expand Down
3 changes: 2 additions & 1 deletion lib/DDGC/Web/Controller/Duckpan.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ sub upload :Chained('logged_in') :Args(0) {
$c->stash->{duckpan_release}->version;
}
$c->d->postman->template_mail(
$c->user->data->{email},
1,
$c->user->email,
'"DuckPAN Indexer" <[email protected]>',
'[DuckPAN] '.$c->stash->{subject},
'duckpan',
Expand Down
1 change: 1 addition & 0 deletions lib/DDGC/Web/Controller/Feedback.pm
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ sub step :Chained('feedback') :PathPart('') :Args(1) {

$c->stash->{c} = $c;
$c->d->postman->template_mail(
1,
$c->d->config->feedback_email,
'"DuckDuckGo Community" <[email protected]>',
'[DDG Feedback '.$c->stash->{feedback_name}.'] '.$data{'1'},
Expand Down
61 changes: 51 additions & 10 deletions lib/DDGC/Web/Controller/InstantAnswer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ sub ia_json :Chained('ia_base') :PathPart('json') :Args(0) {
template => $ia->template,
unsafe => $ia->unsafe,
src_api_documentation => $ia->src_api_documentation,
api_status_page => $ia->api_status_page,
producer => $ia->producer,
designer => $ia->designer,
developer => $ia->developer? from_json($ia->developer) : undef,
Expand Down Expand Up @@ -455,7 +456,14 @@ sub ia_json :Chained('ia_base') :PathPart('json') :Args(0) {
developer => $edited->{developer},
perl_module => $edited->{perl_module},
template => $edited->{template},
repo => $edited->{repo}
repo => $edited->{repo},
answerbar => $edited->{answerbar},
src_api_documentation => $edited->{src_api_documentation},
api_status_page => $edited->{api_status_page},
src_options => $edited->{src_options},
unsafe => $edited->{unsafe},
triggers => $edited->{triggers}->{value},
perl_dependencies => $edited->{perl_dependencies}->{value}
};
}
}
Expand Down Expand Up @@ -509,7 +517,14 @@ sub commit_json :Chained('commit_base') :PathPart('json') :Args(0) {
developer => $ia->developer? from_json($ia->developer) : undef,
template => $ia->template,
tab => $ia->tab,
repo => $ia->repo
repo => $ia->repo,
answerbar => $ia->answerbar,
src_options => $ia->src_options,
src_api_documentation => $ia->src_api_documentation,
api_status_page => $ia->api_status_page,
unsafe => $ia->unsafe,
triggers => $ia->triggers? from_json($ia->triggers) : undef,
perl_dependencies => $ia->perl_dependencies? from_json($ia->perl_dependencies) : undef
);

$edited->{original} = \%original;
Expand Down Expand Up @@ -565,10 +580,6 @@ sub commit_save :Chained('commit_base') :PathPart('save') :Args(0) {
};
}
} else {
if ($field eq 'other_queries') {
$value = to_json($value);
}

if ($field eq "developer" && $value ne '') {
my %dev_hash = (
name => $value,
Expand Down Expand Up @@ -787,24 +798,47 @@ sub current_ia {
my @template = $edits->{'template'};
my @perl_module = $edits->{'perl_module'};
my @repo = $edits->{'repo'};
my @answerbar = $edits->{'answerbar'};
my @src_api_documentation = $edits->{'src_api_documentation'};
my @api_status_page = $edits->{'api_status_page'};
my @src_options = $edits->{'src_options'};
my @unsafe = $edits->{'unsafe'};
my @triggers = $edits->{'triggers'};
my @perl_dependencies = $edits->{'perl_dependencies'};
my %x;

if (ref $edits eq 'HASH') {
my $topic_val = $topic[0][@topic]{'value'};
my $other_q_val = $other_queries[0][@other_queries]{'value'};
my $other_q_edited = $other_q_val? 1 : undef;
my $developer_val = $developer[0][@developer]{'value'};

# Other queries can be empty,
my $answerbar_val = $answerbar[0][@answerbar]{'value'};
my $src_options_val = $src_options[0][@src_options]{'value'};
my $triggers_val = $triggers[0][@triggers]{'value'};
my $triggers_edited = $triggers_val? 1 : undef;
my $perl_dep_val = $perl_dependencies[0][@perl_dependencies]{'value'};
my $perl_dep_edited = $perl_dep_val? 1 : undef;

# Other queries, triggers and perl dependencies can be empty,
# but the handlebars {{#if}} evaluates to false
# for both null and empty values,
# so instead of the value, we check other_queries.edited
# so instead of the value, we check the 'edited' key
# to see if this field was edited
my %other_q = (
edited => $other_q_edited,
value => $other_q_val? from_json($other_q_val) : undef
);

my %triggers_hash = (
edited => $triggers_edited,
value => $triggers_val? from_json($triggers_val) : undef
);

my %perl_dep = (
edited => $perl_dep_edited,
value => $perl_dep_val? from_json($perl_dep_val) : undef
);

%x = (
name => $name[0][@name]{'value'},
description => $desc[0][@desc]{'value'},
Expand All @@ -819,7 +853,14 @@ sub current_ia {
tab => $tab[0][@tab]{'value'},
template => $template[0][@template]{'value'},
perl_module => $perl_module[0][@perl_module]{'value'},
repo => $repo[0][@repo]{'value'}
repo => $repo[0][@repo]{'value'},
answerbar => $answerbar_val? from_json($answerbar_val) : undef,
src_api_documentation => $src_api_documentation[0][@src_api_documentation]{'value'},
api_status_page => $api_status_page[0][@api_status_page]{'value'},
src_options => $src_options_val? from_json($src_options_val) : undef,
unsafe => $unsafe[0][@unsafe]{'value'},
triggers => \%triggers_hash,
perl_dependencies => \%perl_dep
);
}

Expand Down
Loading

0 comments on commit 0c5ef02

Please sign in to comment.