LJSUP-17669: Login.bml form refactoring
[livejournal.git] / cgi-bin / LJ / Event / CommunityJoinRequest.pm
bloba3cc39e0430c627f0eddedcab2d7d885d7b7b577
1 package LJ::Event::CommunityJoinRequest;
2 use strict;
3 use Class::Autouse qw(LJ::Entry);
4 use Carp qw(croak);
5 use base 'LJ::Event';
7 sub new {
8 my ($class, $u, $requestor, $comm) = @_;
10 foreach ($u, $requestor, $comm) {
11 LJ::errobj('Event::CommunityJoinRequest', u => $_)->throw unless LJ::isu($_);
14 # Shouldn't these be method calls? $requestor->id, etc.
15 return $class->SUPER::new($u, $requestor->{userid}, $comm->{userid});
18 sub is_common { 0 }
20 sub comm {
21 my $self = shift;
22 return LJ::load_userid($self->arg2);
25 sub requestor {
26 my $self = shift;
27 return LJ::load_userid($self->arg1);
30 sub authurl {
31 my $self = shift;
33 # we need to force the authaction from the master db; otherwise, replication
34 # delays could cause this to fail initially
35 my $arg = "targetid=". $self->requestor->id;
36 my $auth = LJ::get_authaction($self->comm->id, "comm_join_request", $arg, { force => 1 })
37 or die "Unable to fetch authcode";
39 return "$LJ::SITEROOT/approve/" . $auth->{aaid} . "." . $auth->{authcode};
42 sub as_html {
43 my $self = shift;
44 return sprintf("The user %s has <a href=\"$LJ::SITEROOT/community/pending.bml?authas=%s\">requested to join</a> the community %s.",
45 $self->requestor->ljuser_display, $self->comm->user,
46 $self->comm->ljuser_display);
49 sub tmpl_params {
50 my ($self, $u) = @_;
52 my $lang = $u->prop('browselang') || $LJ::DEFAULT_LANG;
54 return {
55 body => LJ::Lang::get_text($lang, 'esn.comm_join.params.body', undef, {
56 user => $self->requestor->ljuser_display,
57 community => $self->comm->ljuser_display,
58 url => "$LJ::SITEROOT/community/pending.bml?authas=" . $self->comm->user,
59 }),
60 userpic => $self->requestor->userpic ? $self->requestor->userpic->url : '',
61 subject => LJ::Lang::get_text($lang, 'esn.comm_join.params.subject'),
62 actions => [{
63 action_url => $self->requestor->profile_url,
64 action => LJ::Lang::get_text($lang, 'esn.comm_join.actions.view.profile'),
65 },{
66 action_url => "$LJ::SITEROOT/community/pending.bml?authas=" . $self->comm->user,
67 action => LJ::Lang::get_text($lang, 'esn.comm_join.actions.manage.members'),
68 }],
72 sub as_html_actions {
73 my ($self) = @_;
75 my $ret .= "<div class='actions'>";
76 $ret .= " <a href='" . $self->requestor->profile_url . "'>View Profile</a>";
77 $ret .= " <a href='$LJ::SITEROOT/community/pending.bml?authas=" . $self->comm->user . "'>Manage Members</a>";
78 $ret .= "</div>";
80 return $ret;
83 sub content {
84 my ($self, $target) = @_;
86 return $self->as_html_actions;
89 sub as_string {
90 my $self = shift;
91 return sprintf("The user %s has requested to join the community %s.",
92 $self->requestor->display_username,
93 $self->comm->display_username);
96 my @_ml_strings_en = (
97 'esn.community_join_requst.alert', # [[who]] requests membership in [[comm]]. Visit community settings to approve.
98 'esn.community_join_requst.subject', # '[[comm]] membership request by [[who]]!',
99 'esn.manage_membership_reqs', # '[[openlink]]Manage [[communityname]]\'s membership requests[[closelink]]',
100 'esn.manage_community', # '[[openlink]]Manage your communities[[closelink]]',
101 'esn.community_join_requst.email_text', # 'Hi [[maintainer]],
103 #[[username]] has requested to join your community, [[communityname]].
105 #You can:',
107 'esn.comm_join.actions.view.profile', # View Profile
108 'esn.comm_join.actions.manage.members', # Manage Members
109 'esn.comm_join.params.body', # The user [[user]] has <a href="[[url]]">requested to join</a> the community [[community]].
110 'esn.comm_join.params.subject', # Someone has requested to join the community
113 sub as_email_subject {
114 my ($self, $u) = @_;
115 return LJ::Lang::get_text($u->prop('browselang'), 'esn.community_join_requst.subject', undef,
117 comm => $self->comm->display_username,
118 who => $self->requestor->display_username,
122 sub _as_email {
123 my ($self, $u, $is_html) = @_;
125 my $maintainer = $is_html ? ($u->ljuser_display) : ($u->user);
126 my $username = $is_html ? ($self->requestor->ljuser_display) : ($self->requestor->display_username);
127 my $user = $self->requestor->user;
128 my $communityname = $self->comm->user;
129 my $community = $is_html ? ($self->comm->ljuser_display) : ($self->comm->display_username);
130 my $auth_url = $self->authurl;
131 my $rej_url = $auth_url.".".$u->userid;
132 $rej_url =~ s/approve/reject/;
133 my $lang = $u->prop('browselang');
135 # Precache text
136 LJ::Lang::get_text_multi($lang, undef, \@_ml_strings_en);
138 my $vars = {
139 maintainer => $maintainer,
140 username => $username,
141 communityname => $community,
144 return LJ::Lang::get_text($lang, 'esn.community_join_requst.email_text', undef, $vars) .
145 $self->format_options($is_html, $lang, $vars,
147 'esn.manage_request_approve' => [ 1, $auth_url ],
148 'esn.manage_request_reject' => [ 2, $rej_url ],
149 'esn.manage_membership_reqs' => [ 3, "$LJ::SITEROOT/community/pending.bml?authas=$communityname&jumpto=$user" ],
150 'esn.manage_community' => [ 4, "$LJ::SITEROOT/community/manage.bml" ],
155 sub as_email_string {
156 my ($self, $u) = @_;
157 return _as_email($self, $u, 0);
160 sub as_email_html {
161 my ($self, $u) = @_;
162 return _as_email($self, $u, 1);
165 sub as_sms {
166 my ($self, $u) = @_;
167 my $lang = ($u && $u->prop('browselang')) || $LJ::DEFAULT_LANG;
169 # [[requestor]] requests membership in [[comm]]. Visit community settings to approve.
170 return LJ::Lang::get_text($lang, 'notification.sms.communityjoinrequest', undef, {
171 requestor => $self->requestor->display_username(1),
172 comm => $self->comm->display_username(1),
176 sub as_alert {
177 my $self = shift;
178 my $u = shift;
179 return LJ::Lang::get_text($u->prop('browselang'),
180 'esn.community_join_requst.alert', undef,
182 who => $self->requestor->ljuser_display(),
183 comm => $self->comm->ljuser_display(),
187 sub subscription_as_html {
188 my ($class, $subscr) = @_;
189 return LJ::Lang::ml('event.community_join_requst'); # Someone requests membership in a community I maintain';
192 sub available_for_user { 1 }
193 sub is_subscription_visible_to { 1 }
194 sub is_tracking { 0 }
196 sub as_push {
197 my $self = shift;
198 my $u = shift;
199 my $lang = shift;
201 return LJ::Lang::get_text($lang, "esn.push.notification.communityjoinrequest", 1, {
202 user => $self->requestor->user(),
203 community => $self->comm->user(),
207 sub as_push_payload {
208 my $self = shift;
209 my $lang = shift;
211 return { 't' => 15,
212 'j' => $self->comm->user(),
213 'u' => $self->requestor->user(),
218 package LJ::Error::Event::CommunityJoinRequest;
219 sub fields { 'u' }
220 sub as_string {
221 my $self = shift;
222 return "LJ::Event::CommuinityJoinRequest passed bogus u object: $self->{u}";