Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96153102
PhragmentPolicyController.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Dec 23, 05:28
Size
3 KB
Mime Type
text/x-php
Expires
Wed, Dec 25, 05:28 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23125802
Attached To
rPH Phabricator
PhragmentPolicyController.php
View Options
<?php
final
class
PhragmentPolicyController
extends
PhragmentController
{
private
$dblob
;
public
function
willProcessRequest
(
array
$data
)
{
$this
->
dblob
=
idx
(
$data
,
"dblob"
,
""
);
}
public
function
processRequest
()
{
$request
=
$this
->
getRequest
();
$viewer
=
$request
->
getUser
();
$parents
=
$this
->
loadParentFragments
(
$this
->
dblob
);
if
(
$parents
===
null
)
{
return
new
Aphront404Response
();
}
$fragment
=
idx
(
$parents
,
count
(
$parents
)
-
1
,
null
);
$error_view
=
null
;
if
(
$request
->
isFormPost
())
{
$errors
=
array
();
$v_view_policy
=
$request
->
getStr
(
'viewPolicy'
);
$v_edit_policy
=
$request
->
getStr
(
'editPolicy'
);
$v_replace_children
=
$request
->
getBool
(
'replacePoliciesOnChildren'
);
$fragment
->
setViewPolicy
(
$v_view_policy
);
$fragment
->
setEditPolicy
(
$v_edit_policy
);
$fragment
->
save
();
if
(
$v_replace_children
)
{
// If you can edit a fragment, you can forcibly set the policies
// on child fragments, regardless of whether you can see them or not.
$children
=
id
(
new
PhragmentFragmentQuery
())
->
setViewer
(
PhabricatorUser
::
getOmnipotentUser
())
->
withLeadingPath
(
$fragment
->
getPath
().
'/'
)
->
execute
();
$children_phids
=
mpull
(
$children
,
'getPHID'
);
$fragment
->
openTransaction
();
foreach
(
$children
as
$child
)
{
$child
->
setViewPolicy
(
$v_view_policy
);
$child
->
setEditPolicy
(
$v_edit_policy
);
$child
->
save
();
}
$fragment
->
saveTransaction
();
}
return
id
(
new
AphrontRedirectResponse
())
->
setURI
(
'/phragment/browse/'
.
$fragment
->
getPath
());
}
$policies
=
id
(
new
PhabricatorPolicyQuery
())
->
setViewer
(
$viewer
)
->
setObject
(
$fragment
)
->
execute
();
$form
=
id
(
new
AphrontFormView
())
->
setUser
(
$viewer
)
->
appendChild
(
id
(
new
AphrontFormPolicyControl
())
->
setName
(
'viewPolicy'
)
->
setPolicyObject
(
$fragment
)
->
setCapability
(
PhabricatorPolicyCapability
::
CAN_VIEW
)
->
setPolicies
(
$policies
))
->
appendChild
(
id
(
new
AphrontFormPolicyControl
())
->
setName
(
'editPolicy'
)
->
setPolicyObject
(
$fragment
)
->
setCapability
(
PhabricatorPolicyCapability
::
CAN_EDIT
)
->
setPolicies
(
$policies
))
->
appendChild
(
id
(
new
AphrontFormCheckboxControl
())
->
addCheckbox
(
'replacePoliciesOnChildren'
,
'true'
,
pht
(
'Replace policies on child fragments with '
.
'the policies above.'
)))
->
appendChild
(
id
(
new
AphrontFormSubmitControl
())
->
setValue
(
pht
(
'Save Fragment Policies'
))
->
addCancelButton
(
$this
->
getApplicationURI
(
'browse/'
.
$fragment
->
getPath
())));
$crumbs
=
$this
->
buildApplicationCrumbsWithPath
(
$parents
);
$crumbs
->
addTextCrumb
(
pht
(
'Edit Fragment Policies'
));
$box
=
id
(
new
PHUIObjectBoxView
())
->
setHeaderText
(
pht
(
'Edit Fragment Policies: %s'
,
$fragment
->
getPath
()))
->
setValidationException
(
null
)
->
setForm
(
$form
);
return
$this
->
buildApplicationPage
(
array
(
$crumbs
,
$this
->
renderConfigurationWarningIfRequired
(),
$box
),
array
(
'title'
=>
pht
(
'Edit Fragment Policies'
),
'device'
=>
true
));
}
}
Event Timeline
Log In to Comment