Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
aa31260d
Commit
aa31260d
authored
Aug 11, 2014
by
Jan-Willem van der Meer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable unsubscribe for admin emails
parent
44cced4a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
69 additions
and
3 deletions
+69
-3
app/controllers/public/unsubscribes_controller.rb
app/controllers/public/unsubscribes_controller.rb
+24
-0
app/models/user.rb
app/models/user.rb
+5
-0
app/views/public/unsubscribes/show.html.haml
app/views/public/unsubscribes/show.html.haml
+13
-0
app/workers/admin_emails_worker.rb
app/workers/admin_emails_worker.rb
+3
-3
config/routes.rb
config/routes.rb
+2
-0
spec/workers/admin_emails_worker_spec.rb
spec/workers/admin_emails_worker_spec.rb
+22
-0
No files found.
app/controllers/public/unsubscribes_controller.rb
0 → 100644
View file @
aa31260d
module
Public
class
UnsubscribesController
<
ApplicationController
skip_before_filter
:authenticate_user!
,
:reject_blocked
,
:set_current_user_for_observers
,
:add_abilities
layout
'public_users'
def
show
@user
=
get_user
end
def
create
@user
=
get_user
@user
.
admin_unsubscribe!
redirect_to
new_user_session_path
,
notice:
'You have been unsubscribed'
end
protected
def
get_user
@email
=
"
#{
params
[
:email
]
}
.
#{
params
[
:format
]
}
"
User
.
where
(
email:
@email
).
first!
end
end
end
\ No newline at end of file
app/models/user.rb
View file @
aa31260d
...
...
@@ -175,6 +175,7 @@ class User < ActiveRecord::Base
scope
:not_in_project
,
->
(
project
)
{
project
.
users
.
present?
?
where
(
"id not in (:ids)"
,
ids:
project
.
users
.
map
(
&
:id
)
)
:
all
}
scope
:without_projects
,
->
{
where
(
'id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)'
)
}
scope
:ldap
,
->
{
where
(
provider:
'ldap'
)
}
scope
:subscribed_for_admin_email
,
->
{
where
(
admin_email_unsubscribed_at:
nil
)
}
scope
:potential_team_members
,
->
(
team
)
{
team
.
members
.
any?
?
active
.
not_in_team
(
team
)
:
active
}
...
...
@@ -509,4 +510,8 @@ class User < ActiveRecord::Base
def
system_hook_service
SystemHooksService
.
new
end
def
admin_unsubscribe!
update_column
:admin_email_unsubscribed_at
,
Time
.
now
end
end
app/views/public/unsubscribes/show.html.haml
0 → 100644
View file @
aa31260d
%h3
.page-title
Unsubscribe from Admin notifications
%p
Don't want to receive any updates from your system administrator.
By clicking the confirmation button you'll no longer receive these notifications
%hr
=
form_tag
public_unsubscribe_path
(
@email
)
do
%p
Yes, I want to unsubscribe
%strong
=
@email
from any further admin emails.
.form-actions
=
submit_tag
'Unsubscribe'
,
class:
'btn btn-create'
app/workers/admin_emails_worker.rb
View file @
aa31260d
...
...
@@ -11,11 +11,11 @@ class AdminEmailsWorker
def
recipient_list
(
recipient_id
)
case
recipient_id
when
'all'
User
.
where
(
nil
)
User
.
subscribed_for_admin_email
when
/group-(\d+)\z/
Group
.
find
(
$1
).
users
Group
.
find
(
$1
).
users
.
subscribed_for_admin_email
when
/project-(\d+)\z/
Project
.
find
(
$1
).
users
Project
.
find
(
$1
).
users
.
subscribed_for_admin_email
end
end
end
\ No newline at end of file
config/routes.rb
View file @
aa31260d
...
...
@@ -52,6 +52,8 @@ Gitlab::Application.routes.draw do
#
namespace
:public
do
resources
:projects
,
only:
[
:index
]
get
'unsubscribes/:email'
,
to:
'unsubscribes#show'
,
as: :unsubscribe
post
'unsubscribes/:email'
,
to:
'unsubscribes#create'
root
to:
"projects#index"
end
...
...
spec/workers/admin_emails_worker_spec.rb
0 → 100644
View file @
aa31260d
require
'spec_helper'
describe
AdminEmailsWorker
do
context
"recipients"
do
let
(
:recipient_id
)
{
"group-
#{
group
.
id
}
"
}
let
(
:group
)
{
create
:group
}
before
do
2
.
times
do
group
.
add_user
(
create
(
:user
),
Gitlab
::
Access
::
DEVELOPER
)
end
unsubscribed_user
=
create
(
:user
,
admin_email_unsubscribed_at:
5
.
days
.
ago
)
group
.
add_user
(
unsubscribed_user
,
Gitlab
::
Access
::
DEVELOPER
)
ActionMailer
::
Base
.
deliveries
=
[]
end
it
"sends email to subscribed users"
do
AdminEmailsWorker
.
new
.
perform
(
recipient_id
,
'subject'
,
'body'
)
expect
(
ActionMailer
::
Base
.
deliveries
.
count
).
to
eql
2
end
end
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment