Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cancan
Manage
Activity
Members
Plan
External wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Github Mirror
coopdevs
cancan
Commits
55c8a504
Commit
55c8a504
authored
14 years ago
by
stellard
Browse files
Options
Downloads
Patches
Plain Diff
added cannot support and multiple can support
parent
344832d1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/cancan/model_adapters/mongoid_adapter.rb
+14
-6
14 additions, 6 deletions
lib/cancan/model_adapters/mongoid_adapter.rb
spec/cancan/model_adapters/mongoid_adapter_spec.rb
+18
-1
18 additions, 1 deletion
spec/cancan/model_adapters/mongoid_adapter_spec.rb
with
32 additions
and
7 deletions
lib/cancan/model_adapters/mongoid_adapter.rb
+
14
−
6
View file @
55c8a504
...
...
@@ -16,14 +16,22 @@ module CanCan
end
def
database_records
@model_class
.
where
(
conditions
)
if
@rules
.
size
==
0
@model_class
.
where
(
false_query
)
else
criteria
=
@model_class
.
all
@rules
.
each
do
|
rule
|
criteria
=
chain_criteria
(
rule
,
criteria
)
end
criteria
end
end
def
c
onditions
if
@
rule
s
.
size
==
0
false_query
def
c
hain_criteria
rule
,
criteria
if
rule
.
base_behavior
criteria
.
or
(
rule
.
conditions
)
else
@rules
.
first
.
conditions
criteria
.
excludes
(
rule
.
conditions
)
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/cancan/model_adapters/mongoid_adapter_spec.rb
+
18
−
1
View file @
55c8a504
...
...
@@ -56,7 +56,7 @@ if ENV["MODEL_ADAPTER"] == "mongoid"
lord
=
MongoidProject
.
create
(
:title
=>
'Lord'
)
dude
=
MongoidProject
.
create
(
:title
=>
'Dude'
)
MongoidProject
.
accessible_by
(
@ability
,
:read
).
should
==
[
sir
]
MongoidProject
.
accessible_by
(
@ability
,
:read
).
entries
.
should
==
[
sir
]
end
it
"should return everything when the defined ability is manage all"
do
...
...
@@ -154,7 +154,24 @@ if ENV["MODEL_ADAPTER"] == "mongoid"
@ability
.
can
:read
,
MongoidProject
,
:foo
=>
{
:bar
=>
1
}
MongoidProject
.
accessible_by
(
@ability
,
:read
).
entries
.
first
.
should
==
obj
end
it
"should exclude from the result if set to cannot"
do
obj
=
MongoidProject
.
create
(
:bar
=>
1
)
obj2
=
MongoidProject
.
create
(
:bar
=>
2
)
@ability
.
can
:read
,
MongoidProject
@ability
.
cannot
:read
,
MongoidProject
,
:bar
=>
2
MongoidProject
.
accessible_by
(
@ability
,
:read
).
entries
.
first
.
should
==
obj
end
it
"should combine the rules"
do
obj
=
MongoidProject
.
create
(
:bar
=>
1
)
obj2
=
MongoidProject
.
create
(
:bar
=>
2
)
obj3
=
MongoidProject
.
create
(
:bar
=>
3
)
@ability
.
can
:read
,
MongoidProject
,
:bar
=>
1
@ability
.
can
:read
,
MongoidProject
,
:bar
=>
2
MongoidProject
.
accessible_by
(
@ability
,
:read
).
entries
.
should
=~
[
obj
,
obj2
]
end
it
"should not allow to fetch records when ability with just block present"
do
@ability
.
can
:read
,
MongoidProject
do
false
...
...
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