Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
ParsePy
Overview
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
OpenEdx
ParsePy
Commits
2aad3cd1
Commit
2aad3cd1
authored
Nov 07, 2014
by
Dan Krause
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added role and ACL support
parent
1f235380
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
7 deletions
+95
-7
README.mkd
+1
-1
parse_rest/datatypes.py
+59
-6
parse_rest/role.py
+35
-0
No files found.
README.mkd
View file @
2aad3cd1
...
@@ -12,7 +12,7 @@ parse_rest
...
@@ -12,7 +12,7 @@ parse_rest
-
Cloud code integration
-
Cloud code integration
-
Installation querying
-
Installation querying
-
push
-
push
-
**PLANNED/TODO**
:
Roles/ACLs
**
-
Roles/ACLs
**
-
**PLANNED/TODO**
: Image/File type support
-
**PLANNED/TODO**
: Image/File type support
...
...
parse_rest/datatypes.py
View file @
2aad3cd1
...
@@ -32,15 +32,20 @@ class ParseType(object):
...
@@ -32,15 +32,20 @@ class ParseType(object):
type_mapping
=
{}
type_mapping
=
{}
@staticmethod
@staticmethod
def
convert_from_parse
(
parse_data
):
def
convert_from_parse
(
parse_
key
,
parse_
data
):
is_parse_type
=
isinstance
(
parse_data
,
dict
)
and
'__type'
in
parse_data
parse_type
=
None
if
isinstance
(
parse_data
,
dict
):
if
'__type'
in
parse_data
:
parse_type
=
parse_data
.
pop
(
'__type'
)
elif
parse_key
==
'ACL'
:
parse_type
=
'ACL'
# if its not a parse type -- simply return it. This means it wasn't a "special class"
# if its not a parse type -- simply return it. This means it wasn't a "special class"
if
not
is_
parse_type
:
if
not
parse_type
:
return
parse_data
return
parse_data
native
=
ParseType
.
type_mapping
.
get
(
parse_
data
.
pop
(
'__type'
)
)
native
=
ParseType
.
type_mapping
.
get
(
parse_
type
)
return
native
.
from_native
(
**
parse_data
)
if
native
else
parse_data
return
native
.
from_native
(
**
parse_data
)
if
native
else
parse_data
@staticmethod
@staticmethod
...
@@ -60,7 +65,7 @@ class ParseType(object):
...
@@ -60,7 +65,7 @@ class ParseType(object):
ParseResource
:
Pointer
ParseResource
:
Pointer
}
}
if
hasattr
(
python_object
,
'__iter__'
)
and
not
isinstance
(
python_object
,
str
):
if
hasattr
(
python_object
,
'__iter__'
)
and
not
isinstance
(
python_object
,
(
basestring
,
ParseType
)
):
# It's an iterable? Repeat this whole process on each object
# It's an iterable? Repeat this whole process on each object
return
[
ParseType
.
convert_to_parse
(
o
,
as_pointer
=
as_pointer
)
return
[
ParseType
.
convert_to_parse
(
o
,
as_pointer
=
as_pointer
)
for
o
in
python_object
]
for
o
in
python_object
]
...
@@ -203,6 +208,54 @@ class File(ParseType):
...
@@ -203,6 +208,54 @@ class File(ParseType):
_absolute_url
=
property
(
lambda
self
:
self
.
_api_url
)
_absolute_url
=
property
(
lambda
self
:
self
.
_api_url
)
@complex_type
()
class
ACL
(
ParseType
):
@classmethod
def
from_native
(
cls
,
**
kw
):
return
cls
(
kw
)
def
__init__
(
self
,
acl
):
self
.
_acl
=
acl
def
_to_native
(
self
):
return
self
.
_acl
def
__repr__
(
self
):
return
'
%
s(
%
s)'
%
(
type
(
self
)
.
__name__
,
repr
(
self
.
_acl
))
def
set_default
(
self
,
read
=
False
,
write
=
False
):
self
.
_set_permission
(
"*"
,
read
,
write
)
def
set_role
(
self
,
role
,
read
=
False
,
write
=
False
):
if
isinstance
(
role
,
ParseResource
):
self
.
_set_permissions
(
"role:
%
s"
%
role
.
name
,
read
,
write
)
else
:
self
.
_set_permissions
(
"role:
%
s"
%
role
,
read
,
write
)
def
set_user
(
self
,
user
,
read
=
False
,
write
=
False
):
if
isinstance
(
user
,
ParseResource
):
self
.
_set_permission
(
user
.
objectId
,
read
,
write
)
else
:
self
.
_set_permission
(
user
,
read
,
write
)
def
set_all
(
self
,
permissions
):
self
.
_acl
.
clear
()
for
k
,
v
in
permissions
.
items
():
self
.
_set_permission
(
k
,
**
v
)
def
_set_permission
(
self
,
name
,
read
=
False
,
write
=
False
):
permissions
=
{}
if
read
is
True
:
permissions
[
"read"
]
=
True
if
write
is
True
:
permissions
[
"write"
]
=
True
if
len
(
permissions
):
self
.
_acl
[
name
]
=
permissions
else
:
self
.
_acl
.
pop
(
name
,
None
)
class
Function
(
ParseBase
):
class
Function
(
ParseBase
):
ENDPOINT_ROOT
=
'/'
.
join
((
API_ROOT
,
'functions'
))
ENDPOINT_ROOT
=
'/'
.
join
((
API_ROOT
,
'functions'
))
...
@@ -236,7 +289,7 @@ class ParseResource(ParseBase):
...
@@ -236,7 +289,7 @@ class ParseResource(ParseBase):
def
_init_attrs
(
self
,
args
):
def
_init_attrs
(
self
,
args
):
for
key
,
value
in
six
.
iteritems
(
args
):
for
key
,
value
in
six
.
iteritems
(
args
):
setattr
(
self
,
key
,
ParseType
.
convert_from_parse
(
value
))
setattr
(
self
,
key
,
ParseType
.
convert_from_parse
(
key
,
value
))
self
.
_is_loaded
=
True
self
.
_is_loaded
=
True
def
_to_native
(
self
):
def
_to_native
(
self
):
...
...
parse_rest/role.py
0 → 100644
View file @
2aad3cd1
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
parse_rest.connection
import
API_ROOT
from
parse_rest.datatypes
import
ParseResource
from
parse_rest.query
import
QueryManager
class
Role
(
ParseResource
):
'''
A Role is like a regular Parse object (can be modified and saved) but
it requires additional methods and functionality
'''
ENDPOINT_ROOT
=
'/'
.
join
([
API_ROOT
,
'roles'
])
@property
def
className
(
self
):
return
'_Role'
def
__repr__
(
self
):
return
'<Role:
%
s (Id
%
s)>'
%
(
getattr
(
self
,
'name'
,
None
),
self
.
objectId
)
Role
.
Query
=
QueryManager
(
Role
)
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