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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
718b1ddd
Commit
718b1ddd
authored
Jan 26, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Admin::SpamLogsController to block user before destroying
parent
a2bbf004
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
48 deletions
+46
-48
app/controllers/admin/spam_logs_controller.rb
app/controllers/admin/spam_logs_controller.rb
+7
-23
app/models/spam_log.rb
app/models/spam_log.rb
+5
-0
app/views/admin/spam_logs/_spam_log.html.haml
app/views/admin/spam_logs/_spam_log.html.haml
+5
-3
app/views/admin/spam_logs/index.html.haml
app/views/admin/spam_logs/index.html.haml
+1
-1
spec/controllers/admin/spam_logs_controller_spec.rb
spec/controllers/admin/spam_logs_controller_spec.rb
+14
-21
spec/models/spam_log_spec.rb
spec/models/spam_log_spec.rb
+14
-0
No files found.
app/controllers/admin/spam_logs_controller.rb
View file @
718b1ddd
class
Admin::SpamLogsController
<
Admin
::
ApplicationController
class
Admin::SpamLogsController
<
Admin
::
ApplicationController
before_action
:set_spam_log
,
only:
[
:destroy
]
def
index
def
index
@spam_logs
=
SpamLog
.
order
(
created_at
: :desc
).
page
(
params
[
:page
])
@spam_logs
=
SpamLog
.
order
(
id
: :desc
).
page
(
params
[
:page
])
end
end
def
destroy
def
destroy
@spam_log
.
destroy
spam_log
=
SpamLog
.
find
(
params
[
:id
])
message
=
'Spam log was successfully destroyed.'
if
params
[
:remove_user
]
if
params
[
:remove_user
]
username
=
@spam_log
.
user
.
username
spam_log
.
remove_user
@spam_log
.
user
.
destroy
redirect_to
admin_spam_logs_path
,
notice:
"User
#{
spam_log
.
user
.
username
}
was successfully removed."
message
=
"User
#{
username
}
was successfully destroyed."
else
end
spam_log
.
destroy
render
nothing:
true
respond_to
do
|
format
|
format
.
json
{
render
json:
'{}'
}
format
.
html
{
redirect_to
admin_spam_logs_path
,
notice:
message
}
end
end
end
end
private
def
set_spam_log
@spam_log
=
SpamLog
.
find
(
params
[
:id
])
end
def
spam_log_params
params
[
:spam_log
]
end
end
end
app/models/spam_log.rb
View file @
718b1ddd
...
@@ -2,4 +2,9 @@ class SpamLog < ActiveRecord::Base
...
@@ -2,4 +2,9 @@ class SpamLog < ActiveRecord::Base
belongs_to
:user
belongs_to
:user
validates
:user
,
presence:
true
validates
:user
,
presence:
true
def
remove_user
user
.
block
user
.
destroy
end
end
end
app/views/admin/spam_logs/_spam_log.html.haml
View file @
718b1ddd
...
@@ -4,13 +4,15 @@
...
@@ -4,13 +4,15 @@
=
time_ago_with_tooltip
(
spam_log
.
created_at
)
=
time_ago_with_tooltip
(
spam_log
.
created_at
)
%td
%td
-
if
user
-
if
user
=
link_to
user
.
name
,
user
=
link_to
user
.
name
,
[
:admin
,
user
]
.light.small
Joined
#{
time_ago_with_tooltip
(
user
.
created_at
)
}
-
else
-
else
(removed)
(removed)
%td
%td
=
spam_log
.
source_ip
=
spam_log
.
source_ip
%td
%td
=
spam_log
.
via_api
?
'Y'
:
'N'
=
spam_log
.
via_api
?
?
'Y'
:
'N'
%td
%td
=
spam_log
.
noteable_type
=
spam_log
.
noteable_type
%td
%td
...
@@ -27,4 +29,4 @@
...
@@ -27,4 +29,4 @@
-
else
-
else
.btn.btn-xs.disabled
.btn.btn-xs.disabled
Already Blocked
Already Blocked
=
link_to
'Remove log'
,
[
:admin
,
spam_log
,
format: :json
],
remote:
true
,
method: :delete
,
class:
"btn btn-xs btn-close js-remove-tr"
=
link_to
'Remove log'
,
[
:admin
,
spam_log
],
remote:
true
,
method: :delete
,
class:
"btn btn-xs btn-close js-remove-tr"
app/views/admin/spam_logs/index.html.haml
View file @
718b1ddd
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
%th
Date
%th
Date
%th
User
%th
User
%th
Source IP
%th
Source IP
%th
Via
API?
%th
API?
%th
Type
%th
Type
%th
Title
%th
Title
%th
Description
%th
Description
...
...
spec/controllers/admin/spam_logs_controller_spec.rb
View file @
718b1ddd
require
'spec_helper'
require
'spec_helper'
describe
Admin
::
SpamLogsController
do
describe
Admin
::
SpamLogsController
do
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:spam_log
)
{
create
(
:spam_log
,
user:
admin
)
}
let
(
:user
)
{
create
(
:user
)
}
let!
(
:first_spam
)
{
create
(
:spam_log
,
user:
user
)
}
let!
(
:second_spam
)
{
create
(
:spam_log
,
user:
user
)
}
before
do
before
do
sign_in
(
admin
)
sign_in
(
admin
)
...
@@ -11,37 +13,28 @@ describe Admin::SpamLogsController do
...
@@ -11,37 +13,28 @@ describe Admin::SpamLogsController do
describe
'#index'
do
describe
'#index'
do
it
'lists all spam logs'
do
it
'lists all spam logs'
do
get
:index
get
:index
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
end
end
end
end
describe
'#destroy'
do
describe
'#destroy'
do
it
'destroys just spam log'
do
it
'removes only the spam log when removing log'
do
user
=
spam_log
.
user
expect
{
delete
:destroy
,
id:
spam_log
.
id
delete
:destroy
,
id:
first_spam
.
id
}.
to
change
{
SpamLog
.
count
}.
by
(
-
1
)
expect
(
SpamLog
.
all
.
count
).
to
eq
(
0
)
expect
(
User
.
find
(
user
.
id
)).
to
be_truthy
expect
(
User
.
find
(
user
.
id
)).
to
be_truthy
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
.
status
).
to
eq
(
200
)
end
end
it
'destroys user and his spam logs'
do
it
'removes user and his spam logs when removing the user'
do
user
=
spam_log
.
user
delete
:destroy
,
id:
first_spam
.
id
,
remove_user:
true
delete
:destroy
,
id:
spam_log
.
id
,
remove_user:
true
expect
(
SpamLog
.
all
.
count
).
to
eq
(
0
)
expect
(
flash
[
:notice
]).
to
eq
"User
#{
user
.
username
}
was successfully removed."
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
.
status
).
to
eq
(
302
)
end
expect
(
SpamLog
.
count
).
to
eq
(
0
)
it
'destroys user and his spam logs with JSON format'
do
user
=
spam_log
.
user
delete
:destroy
,
id:
spam_log
.
id
,
remove_user:
true
,
format: :json
expect
(
SpamLog
.
all
.
count
).
to
eq
(
0
)
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
expect
(
JSON
.
parse
(
response
.
body
)).
to
eq
({})
expect
(
response
.
status
).
to
eq
(
200
)
end
end
end
end
end
end
spec/models/spam_log_spec.rb
View file @
718b1ddd
...
@@ -8,4 +8,18 @@ describe SpamLog, models: true do
...
@@ -8,4 +8,18 @@ describe SpamLog, models: true do
describe
'validations'
do
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
end
end
describe
'#remove_user'
do
it
'blocks the user'
do
spam_log
=
build
(
:spam_log
)
expect
{
spam_log
.
remove_user
}.
to
change
{
spam_log
.
user
.
blocked?
}.
to
(
true
)
end
it
'removes the user'
do
spam_log
=
build
(
:spam_log
)
expect
{
spam_log
.
remove_user
}.
to
change
{
User
.
count
}.
by
(
-
1
)
end
end
end
end
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