Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
39ab3eaf
Commit
39ab3eaf
authored
Mar 29, 2017
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Some pure functions (unfinished yet) to manage rights.
parent
2f68aa2a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
32 deletions
+33
-32
nodes.py
gargantext/models/nodes.py
+1
-1
users.py
gargantext/models/users.py
+24
-23
http.py
gargantext/util/http.py
+3
-3
nodes.py
gargantext/views/api/nodes.py
+5
-5
No files found.
gargantext/models/nodes.py
View file @
39ab3eaf
...
...
@@ -33,7 +33,7 @@ class Node(Base):
parent_id
=
Column
(
Integer
,
ForeignKey
(
'nodes.id'
,
ondelete
=
'CASCADE'
))
# main data
name
=
Column
(
String
(
255
))
date
=
Column
(
DateTime
(),
default
=
datetime
.
now
)
date
=
Column
(
DateTime
(),
default
=
datetime
.
now
)
# metadata (see https://bashelton.com/2014/03/updating-postgresql-json-fields-via-sqlalchemy/)
hyperdata
=
Column
(
JSONB
,
default
=
dict
)
...
...
gargantext/models/users.py
View file @
39ab3eaf
...
...
@@ -123,18 +123,19 @@ class User(Base):
def
pending_invitations
(
self
):
""" Get invitations that have not been accepted nor refused.
"""
Friend
=
aliased
(
User
)
Contact1
=
aliased
(
Contact
)
Contact2
=
aliased
(
Contact
)
# outerjoin
query
=
(
session
.
query
(
Friend
)
.
join
(
Contact1
,
Contact1
.
user2_id
==
Friend
.
id
)
.
join
(
Contact2
,
Contact2
.
user1_id
==
Friend
.
id
)
.
filter
(
Contact1
.
user1_id
==
self
.
id
,
Contact1
.
is_blocked
==
False
)
.
filter
(
Contact2
.
user2_id
==
self
.
id
)
)
return
query
.
all
()
undefined
# Friend = aliased(User)
# Contact1 = aliased(Contact)
# Contact2 = aliased(Contact)
# # TODO outerjoin
# query = (session
# .query(Friend)
# .join(Contact1, Contact1.user2_id == Friend.id)
# .join(Contact2, Contact2.user1_id == Friend.id)
# .filter(Contact1.user1_id == self.id, Contact1.is_blocked == False)
# .filter(Contact2.user2_id == self.id)
# )
# return query.all()
...
...
@@ -151,17 +152,17 @@ class User(Base):
# node.id in (contact.id for contact in self.friends())
#
Deprecated
#
def contacts_nodes(self, typename=None):
#
from .nodes import Node
# for contact in self.contact
s():
#
contact_nodes = (session
#
.query(Node)
#
.filter(Node.user_id == contact.id)
#
.filter(Node.typename == typename)
#
.order_by(Node.date)
#
).all()
#
yield contact, contact_nodes
#
TODO add the right management toolbox
def
contacts_nodes
(
self
,
typename
=
None
):
from
.nodes
import
Node
for
contact
in
self
.
friend
s
():
contact_nodes
=
(
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
contact
.
id
)
.
filter
(
Node
.
typename
==
typename
)
.
order_by
(
Node
.
date
)
)
.
all
()
yield
contact
,
contact_nodes
...
...
gargantext/util/http.py
View file @
39ab3eaf
...
...
@@ -27,15 +27,15 @@ def requires_auth(func):
# user was authenticated but something made the session expire
except
DetachedInstanceError
as
die
:
print
(
"===
\n
Detached instance error: trying to rollback session"
)
print
(
"===
Warning:
\n
Detached instance error: trying to rollback session"
)
print
(
die
)
from
gargantext.util.db
import
session
session
.
rollback
()
print
(
"=== session rollback ok!"
)
print
(
"===
Info:
\n
session rollback ok!"
)
# re init the global cache (it must still have detached instances)
from
gargantext.util.db_cache
import
cache
cache
.
clean_all
()
print
(
"=== cache reinit ok!"
)
print
(
"===
Info:
\n
cache reinit ok!"
)
# and relogin for safety
url
=
'/auth/login/?next=
%
s'
%
urlencode
(
request
.
path
)
return
redirect
(
url
)
...
...
gargantext/views/api/nodes.py
View file @
39ab3eaf
...
...
@@ -26,7 +26,7 @@ _hyperdata_available_fields = ['title', 'source', 'abstract', 'statuses',
def
check_rights
(
request
,
node_id
=
None
):
def
check_rights
(
request
,
mode
=
"read"
,
node_id
=
None
):
"""
check rights of a request and maybe a node if given as parameters.
...
...
@@ -54,14 +54,14 @@ def check_rights(request, node_id=None):
.
filter
(
NodeUser
.
node_id
==
node_id
)
.
first
(
)
)
print
(
nodeRights
.
mode
)
# If the user is anonymous
# Is the user authenticated i.e. anonymous ?
if
request
.
user
.
id
is
None
and
nodeRights
is
not
None
:
# if request.user.id is None and nodeRights not defined then False
# Check if the node has public rights
if
int
(
str
(
nodeRights
.
mode
)[
2
])
==
4
:
if
nodeRights
.
mode_others
==
4
:
return
True
else
:
return
False
...
...
@@ -72,10 +72,10 @@ def check_rights(request, node_id=None):
# Is the user owner of the node ?
if
nodeRights
.
user_id
==
request
.
user
.
id
:
# Has the user the rights to read the Node ?
if
int
(
str
(
nodeRights
.
mode
)[
0
])
==
7
:
if
nodeRights
.
mode_user
==
7
:
return
True
elif
int
(
str
(
nodeRights
.
mode
)[
1
])
==
7
:
elif
nodeRights
.
mode_group
==
7
:
# Is the user owner of the node ?
return
True
else
:
...
...
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