Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F94028269
PhabricatorOAuthServerEditor.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
Tue, Dec 3, 08:48
Size
4 KB
Mime Type
text/x-php
Expires
Thu, Dec 5, 08:48 (2 d)
Engine
blob
Format
Raw Data
Handle
22715687
Attached To
rPH Phabricator
PhabricatorOAuthServerEditor.php
View Options
<?php
final
class
PhabricatorOAuthServerEditor
extends
PhabricatorApplicationTransactionEditor
{
public
function
getEditorApplicationClass
()
{
return
'PhabricatorOAuthServerApplication'
;
}
public
function
getEditorObjectsDescription
()
{
return
pht
(
'OAuth Applications'
);
}
public
function
getTransactionTypes
()
{
$types
=
parent
::
getTransactionTypes
();
$types
[]
=
PhabricatorOAuthServerTransaction
::
TYPE_NAME
;
$types
[]
=
PhabricatorOAuthServerTransaction
::
TYPE_REDIRECT_URI
;
$types
[]
=
PhabricatorTransactions
::
TYPE_VIEW_POLICY
;
$types
[]
=
PhabricatorTransactions
::
TYPE_EDIT_POLICY
;
return
$types
;
}
protected
function
getCustomTransactionOldValue
(
PhabricatorLiskDAO
$object
,
PhabricatorApplicationTransaction
$xaction
)
{
switch
(
$xaction
->
getTransactionType
())
{
case
PhabricatorOAuthServerTransaction
::
TYPE_NAME
:
return
$object
->
getName
();
case
PhabricatorOAuthServerTransaction
::
TYPE_REDIRECT_URI
:
return
$object
->
getRedirectURI
();
}
}
protected
function
getCustomTransactionNewValue
(
PhabricatorLiskDAO
$object
,
PhabricatorApplicationTransaction
$xaction
)
{
switch
(
$xaction
->
getTransactionType
())
{
case
PhabricatorOAuthServerTransaction
::
TYPE_NAME
:
case
PhabricatorOAuthServerTransaction
::
TYPE_REDIRECT_URI
:
return
$xaction
->
getNewValue
();
}
}
protected
function
applyCustomInternalTransaction
(
PhabricatorLiskDAO
$object
,
PhabricatorApplicationTransaction
$xaction
)
{
switch
(
$xaction
->
getTransactionType
())
{
case
PhabricatorOAuthServerTransaction
::
TYPE_NAME
:
$object
->
setName
(
$xaction
->
getNewValue
());
return
;
case
PhabricatorOAuthServerTransaction
::
TYPE_REDIRECT_URI
:
$object
->
setRedirectURI
(
$xaction
->
getNewValue
());
return
;
}
return
parent
::
applyCustomInternalTransaction
(
$object
,
$xaction
);
}
protected
function
applyCustomExternalTransaction
(
PhabricatorLiskDAO
$object
,
PhabricatorApplicationTransaction
$xaction
)
{
switch
(
$xaction
->
getTransactionType
())
{
case
PhabricatorOAuthServerTransaction
::
TYPE_NAME
:
case
PhabricatorOAuthServerTransaction
::
TYPE_REDIRECT_URI
:
return
;
}
return
parent
::
applyCustomExternalTransaction
(
$object
,
$xaction
);
}
protected
function
validateTransaction
(
PhabricatorLiskDAO
$object
,
$type
,
array
$xactions
)
{
$errors
=
parent
::
validateTransaction
(
$object
,
$type
,
$xactions
);
switch
(
$type
)
{
case
PhabricatorOAuthServerTransaction
::
TYPE_NAME
:
$missing
=
$this
->
validateIsEmptyTextField
(
$object
->
getName
(),
$xactions
);
if
(
$missing
)
{
$error
=
new
PhabricatorApplicationTransactionValidationError
(
$type
,
pht
(
'Required'
),
pht
(
'OAuth applications must have a name.'
),
nonempty
(
last
(
$xactions
),
null
));
$error
->
setIsMissingFieldError
(
true
);
$errors
[]
=
$error
;
}
break
;
case
PhabricatorOAuthServerTransaction
::
TYPE_REDIRECT_URI
:
$missing
=
$this
->
validateIsEmptyTextField
(
$object
->
getRedirectURI
(),
$xactions
);
if
(
$missing
)
{
$error
=
new
PhabricatorApplicationTransactionValidationError
(
$type
,
pht
(
'Required'
),
pht
(
'OAuth applications must have a valid redirect URI.'
),
nonempty
(
last
(
$xactions
),
null
));
$error
->
setIsMissingFieldError
(
true
);
$errors
[]
=
$error
;
}
else
{
foreach
(
$xactions
as
$xaction
)
{
$redirect_uri
=
$xaction
->
getNewValue
();
try
{
$server
=
new
PhabricatorOAuthServer
();
$server
->
assertValidRedirectURI
(
$redirect_uri
);
}
catch
(
Exception
$ex
)
{
$errors
[]
=
new
PhabricatorApplicationTransactionValidationError
(
$type
,
pht
(
'Invalid'
),
$ex
->
getMessage
(),
$xaction
);
}
}
}
break
;
}
return
$errors
;
}
}
Event Timeline
Log In to Comment