Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
40eb1166
Commit
40eb1166
authored
Apr 04, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Splitted saveRule into insertRule and updateRule
parent
f3dd74ff
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
16 deletions
+59
-16
DbManager.php
framework/rbac/DbManager.php
+12
-6
Manager.php
framework/rbac/Manager.php
+11
-3
PhpManager.php
framework/rbac/PhpManager.php
+15
-1
ManagerTestCase.php
tests/unit/framework/rbac/ManagerTestCase.php
+21
-6
No files found.
framework/rbac/DbManager.php
View file @
40eb1166
...
@@ -631,14 +631,20 @@ class DbManager extends Manager
...
@@ -631,14 +631,20 @@ class DbManager extends Manager
*
*
* @param Rule $rule the rule that has been changed.
* @param Rule $rule the rule that has been changed.
*/
*/
public
function
save
Rule
(
Rule
$rule
)
public
function
insert
Rule
(
Rule
$rule
)
{
{
$data
=
serialize
(
$rule
);
$this
->
db
->
createCommand
()
->
insert
(
$this
->
ruleTable
,
[
'name'
=>
$rule
->
name
,
'data'
=>
serialize
(
$rule
)])
->
execute
();
try
{
$this
->
db
->
createCommand
()
->
insert
(
$this
->
ruleTable
,
[
'name'
=>
$rule
->
name
,
'data'
=>
$data
])
->
execute
();
}
catch
(
\yii\db\Exception
$e
)
{
$this
->
db
->
createCommand
()
->
update
(
$this
->
ruleTable
,
[
'data'
=>
$data
],
[
'name'
=>
$rule
->
name
])
->
execute
();
}
}
/**
* Updates existing rule.
*
* @param string $name the name of the rule to update
* @param Rule $rule new rule
*/
public
function
updateRule
(
$name
,
Rule
$rule
)
{
$this
->
db
->
createCommand
()
->
update
(
$this
->
ruleTable
,
[
'name'
=>
$rule
->
name
,
'data'
=>
serialize
(
$rule
)],
[
'name'
=>
$name
])
->
execute
();
}
}
/**
/**
...
...
framework/rbac/Manager.php
View file @
40eb1166
...
@@ -323,11 +323,19 @@ abstract class Manager extends Component
...
@@ -323,11 +323,19 @@ abstract class Manager extends Component
abstract
public
function
removeRule
(
$name
);
abstract
public
function
removeRule
(
$name
);
/**
/**
*
Saves the changes to the
rule.
*
Inserts new
rule.
*
*
* @param Rule $rule the rule that
has been chang
ed.
* @param Rule $rule the rule that
needs to be stor
ed.
*/
*/
abstract
public
function
saveRule
(
Rule
$rule
);
abstract
public
function
insertRule
(
Rule
$rule
);
/**
* Updates existing rule.
*
* @param string $name the name of the rule to update
* @param Rule $rule new rule
*/
abstract
public
function
updateRule
(
$name
,
Rule
$rule
);
/**
/**
* Returns rule given its name.
* Returns rule given its name.
...
...
framework/rbac/PhpManager.php
View file @
40eb1166
...
@@ -601,12 +601,26 @@ class PhpManager extends Manager
...
@@ -601,12 +601,26 @@ class PhpManager extends Manager
*
*
* @param Rule $rule the rule that has been changed.
* @param Rule $rule the rule that has been changed.
*/
*/
public
function
save
Rule
(
Rule
$rule
)
public
function
insert
Rule
(
Rule
$rule
)
{
{
$this
->
_rules
[
$rule
->
name
]
=
$rule
;
$this
->
_rules
[
$rule
->
name
]
=
$rule
;
}
}
/**
/**
* Updates existing rule.
*
* @param string $name the name of the rule to update
* @param Rule $rule new rule
*/
public
function
updateRule
(
$name
,
Rule
$rule
)
{
if
(
$rule
->
name
!==
$name
)
{
unset
(
$this
->
_rules
[
$name
]);
}
$this
->
_rules
[
$rule
->
name
]
=
$rule
;
}
/**
* Returns rule given its name.
* Returns rule given its name.
*
*
* @param string $name name of the rule.
* @param string $name name of the rule.
...
...
tests/unit/framework/rbac/ManagerTestCase.php
View file @
40eb1166
...
@@ -178,29 +178,44 @@ abstract class ManagerTestCase extends TestCase
...
@@ -178,29 +178,44 @@ abstract class ManagerTestCase extends TestCase
$this
->
assertNull
(
$rule
);
$this
->
assertNull
(
$rule
);
}
}
public
function
test
Save
Rule
()
public
function
test
Insert
Rule
()
{
{
$ruleName
=
'isReallyReallyAuthor'
;
$ruleName
=
'isReallyReallyAuthor'
;
$rule
=
new
AuthorRule
([
'name'
=>
$ruleName
,
'reallyReally'
=>
true
]);
$rule
=
new
AuthorRule
([
'name'
=>
$ruleName
,
'reallyReally'
=>
true
]);
$this
->
auth
->
save
Rule
(
$rule
);
$this
->
auth
->
insert
Rule
(
$rule
);
/** @var AuthorRule $rule */
/** @var AuthorRule $rule */
$rule
=
$this
->
auth
->
getRule
(
$ruleName
);
$rule
=
$this
->
auth
->
getRule
(
$ruleName
);
$this
->
assertEquals
(
$ruleName
,
$rule
->
name
);
$this
->
assertEquals
(
$ruleName
,
$rule
->
name
);
$this
->
assertEquals
(
true
,
$rule
->
reallyReally
);
$this
->
assertEquals
(
true
,
$rule
->
reallyReally
);
}
public
function
testUpdateRule
()
{
$rule
=
$this
->
auth
->
getRule
(
'isAuthor'
);
$rule
->
name
=
"newName"
;
$rule
->
reallyReally
=
false
;
$rule
->
reallyReally
=
false
;
$this
->
auth
->
saveRule
(
$rule
);
$this
->
auth
->
updateRule
(
'isAuthor'
,
$rule
);
/** @var AuthorRule $rule */
/** @var AuthorRule $rule */
$rule
=
$this
->
auth
->
getRule
(
$ruleName
);
$rule
=
$this
->
auth
->
getRule
(
'isAuthor'
);
$this
->
assertEquals
(
null
,
$rule
);
$rule
=
$this
->
auth
->
getRule
(
'newName'
);
$this
->
assertEquals
(
"newName"
,
$rule
->
name
);
$this
->
assertEquals
(
false
,
$rule
->
reallyReally
);
$this
->
assertEquals
(
false
,
$rule
->
reallyReally
);
$rule
->
reallyReally
=
true
;
$this
->
auth
->
updateRule
(
'newName'
,
$rule
);
$rule
=
$this
->
auth
->
getRule
(
'newName'
);
$this
->
assertEquals
(
true
,
$rule
->
reallyReally
);
}
}
public
function
testGetRules
()
public
function
testGetRules
()
{
{
$rule
=
new
AuthorRule
([
'name'
=>
'isReallyReallyAuthor'
,
'reallyReally'
=>
true
]);
$rule
=
new
AuthorRule
([
'name'
=>
'isReallyReallyAuthor'
,
'reallyReally'
=>
true
]);
$this
->
auth
->
save
Rule
(
$rule
);
$this
->
auth
->
insert
Rule
(
$rule
);
$rules
=
$this
->
auth
->
getRules
();
$rules
=
$this
->
auth
->
getRules
();
...
@@ -281,7 +296,7 @@ abstract class ManagerTestCase extends TestCase
...
@@ -281,7 +296,7 @@ abstract class ManagerTestCase extends TestCase
protected
function
prepareData
()
protected
function
prepareData
()
{
{
$this
->
auth
->
save
Rule
(
new
AuthorRule
());
$this
->
auth
->
insert
Rule
(
new
AuthorRule
());
$this
->
auth
->
createOperation
(
'createPost'
,
'create a post'
);
$this
->
auth
->
createOperation
(
'createPost'
,
'create a post'
);
$this
->
auth
->
createOperation
(
'readPost'
,
'read a post'
);
$this
->
auth
->
createOperation
(
'readPost'
,
'read a post'
);
...
...
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