Cross Reference: access_scopes_for_repository_associations.rb
xref
: /
ontohub
/
lib
/
access_scopes_for_repository_associations.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
access_scopes_for_repository_associations.rb revision ab2be9b1453256821fb11be230149c49963a7b69
# This module is supposed to be included into other model classes to define the
# scopes :pub and :accessible_by
module
AccessScopesForRepositoryAssociations
extend
ActiveSupport
::
Concern
included
do
# access scopes
scope
:
pub
, ->
do
joins
(:
repository
)
.
# simulating scope:
repository.active
where
(
'
repositories.is
_destroying = ?'
,
false
)
.
where
(
"
repositories.access
NOT LIKE 'private%'"
)
end
scope
:
accessible_by
, ->
(
user
)
do
if
user
joins
(:
repository
)
.
# simulating scope:
repository.active
where
(
'
repositories.is
_destroying = ?'
,
false
)
.
where
(
Repository
::
ACCESSIBLE_BY_SQL_QUERY
,
user
,
user
)
else
pub
end
end
end
end