Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mastofe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pleroma
mastofe
Commits
e031fd60
Commit
e031fd60
authored
7 years ago
by
Jack Jennings
Committed by
Eugen Rochko
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Move status reblog authorization into policy (#3425)
parent
bc4fad9e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/policies/status_policy.rb
+16
-2
16 additions, 2 deletions
app/policies/status_policy.rb
app/services/reblog_service.rb
+1
-2
1 addition, 2 deletions
app/services/reblog_service.rb
spec/policies/status_policy_spec.rb
+25
-7
25 additions, 7 deletions
spec/policies/status_policy_spec.rb
with
42 additions
and
11 deletions
app/policies/status_policy.rb
+
16
−
2
View file @
e031fd60
...
...
@@ -9,12 +9,26 @@ class StatusPolicy
end
def
show?
if
status
.
direct_visibility
?
if
direct
?
status
.
account
.
id
==
account
&
.
id
||
status
.
mentions
.
where
(
account:
account
).
exists?
elsif
status
.
private_visibility
?
elsif
private
?
status
.
account
.
id
==
account
&
.
id
||
account
&
.
following?
(
status
.
account
)
||
status
.
mentions
.
where
(
account:
account
).
exists?
else
account
.
nil?
||
!
status
.
account
.
blocking?
(
account
)
end
end
def
reblog?
!
direct?
&&
!
private
?
&&
show?
end
private
def
direct?
status
.
direct_visibility?
end
def
private?
status
.
private_visibility?
end
end
This diff is collapsed.
Click to expand it.
app/services/reblog_service.rb
+
1
−
2
View file @
e031fd60
...
...
@@ -11,8 +11,7 @@ class ReblogService < BaseService
def
call
(
account
,
reblogged_status
)
reblogged_status
=
reblogged_status
.
reblog
if
reblogged_status
.
reblog?
authorize_with
account
,
reblogged_status
,
:show?
raise
Mastodon
::
NotPermittedError
if
reblogged_status
.
direct_visibility?
||
reblogged_status
.
private_visibility?
authorize_with
account
,
reblogged_status
,
:reblog?
reblog
=
account
.
statuses
.
create!
(
reblog:
reblogged_status
,
text:
''
)
...
...
This diff is collapsed.
Click to expand it.
spec/policies/status_policy_spec.rb
+
25
−
7
View file @
e031fd60
...
...
@@ -7,6 +7,20 @@ RSpec.describe StatusPolicy, type: :model do
let
(
:alice
)
{
Fabricate
(
:account
,
username:
'alice'
)
}
let
(
:status
)
{
Fabricate
(
:status
,
account:
alice
)
}
permissions
:show?
,
:reblog?
do
it
'grants access when no viewer'
do
expect
(
subject
).
to
permit
(
nil
,
status
)
end
it
'denies access when viewer is blocked'
do
block
=
Fabricate
(
:block
)
status
.
visibility
=
:private
status
.
account
=
block
.
target_account
expect
(
subject
).
to_not
permit
(
block
.
account
,
status
)
end
end
permissions
:show?
do
it
'grants access when direct and account is viewer'
do
status
.
visibility
=
:direct
...
...
@@ -54,17 +68,21 @@ RSpec.describe StatusPolicy, type: :model do
expect
(
subject
).
to_not
permit
(
viewer
,
status
)
end
end
it
'grants access when no viewer'
do
expect
(
subject
).
to
permit
(
nil
,
status
)
permissions
:reblog?
do
it
'denies access when private'
do
viewer
=
Fabricate
(
:account
)
status
.
visibility
=
:private
expect
(
subject
).
to_not
permit
(
viewer
,
status
)
end
it
'denies access when viewer is blocked'
do
block
=
Fabricate
(
:block
)
status
.
visibility
=
:private
status
.
account
=
block
.
target_account
it
'denies access when direct'
do
viewer
=
Fabricate
(
:account
)
status
.
visibility
=
:direct
expect
(
subject
).
to_not
permit
(
block
.
account
,
status
)
expect
(
subject
).
to_not
permit
(
viewer
,
status
)
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment