Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2331358
PhragmentPolicyController.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
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
));
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Sep 16, 7:36 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
441363
Default Alt Text
PhragmentPolicyController.php (3 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment