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
30c7569c
Commit
30c7569c
authored
Mar 27, 2017
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Collaborative: Adding friends requests.
parent
e99f2815
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
28 deletions
+109
-28
nodes.py
gargantext/models/nodes.py
+6
-4
users.py
gargantext/models/users.py
+103
-24
No files found.
gargantext/models/nodes.py
View file @
30c7569c
...
...
@@ -221,9 +221,11 @@ class NodeUser(Base):
"""
__tablename__
=
'node_user'
node_id
=
Column
(
Integer
,
ForeignKey
(
Node
.
id
,
ondelete
=
'CASCADE'
),
primary_key
=
True
)
user_id
=
Column
(
Integer
,
ForeignKey
(
User
.
id
,
ondelete
=
'CASCADE'
))
group_id
=
Column
(
Integer
,
ForeignKey
(
User
.
id
,
ondelete
=
'CASCADE'
))
mode
=
Column
(
Integer
)
node_id
=
Column
(
Integer
,
ForeignKey
(
Node
.
id
,
ondelete
=
'CASCADE'
),
primary_key
=
True
)
user_id
=
Column
(
Integer
,
ForeignKey
(
User
.
id
,
ondelete
=
'CASCADE'
))
group_id
=
Column
(
Integer
,
ForeignKey
(
User
.
id
,
ondelete
=
'CASCADE'
))
rules_user
=
Column
(
Integer
)
rules_group
=
Column
(
Integer
)
rules_others
=
Column
(
Integer
)
gargantext/models/users.py
View file @
30c7569c
...
...
@@ -20,15 +20,8 @@ class User(Base):
last_login
=
Column
(
DateTime
(
timezone
=
False
))
date_joined
=
Column
(
DateTime
(
timezone
=
False
),
default
=
datetime
.
now
)
def
contacts
(
self
):
"""get all contacts in relation with the user"""
Friend
=
aliased
(
User
)
query
=
(
session
.
query
(
Friend
)
.
join
(
Contact
,
Contact
.
user2_id
==
Friend
.
id
)
.
filter
(
Contact
.
user1_id
==
self
.
id
)
)
return
query
.
all
()
def
get_params
(
self
,
username
=
None
):
return
self
.
__dict__
.
items
()
def
nodes
(
self
,
typename
=
None
,
order
=
None
):
"""get all nodes belonging to the user
...
...
@@ -46,26 +39,112 @@ class User(Base):
query
=
query
.
order_by
(
Node
.
name
)
return
query
def
invite
(
self
,
username
=
None
,
block
=
False
,
notification
=
True
):
if
username
is
None
:
raise
ValueError
(
'if you contact someone give his username please.'
)
if
username
is
self
.
username
:
raise
ValueError
(
'Why self contact should be implemented ?'
)
maybeFriend
=
session
.
query
(
User
)
.
filter
(
User
.
username
==
username
)
.
first
()
if
maybeFriend
is
None
:
raise
ValueError
(
'username unknown in database.'
)
relation
=
(
session
.
query
(
Contact
)
.
filter
(
user1_id
==
self
.
id
,
user2_id
==
maybeFriend
.
id
)
.
first
()
)
if
relation
is
not
None
:
if
relation
.
is_blocked
!=
block
:
relation
.
is_blocked
=
block
session
.
add
(
relation
)
session
.
commit
()
print
(
'Link does exist already and updated'
)
else
:
print
(
'Link does exist already and not updated'
)
else
:
relation
=
Contact
()
relation
.
user1_id
=
self
.
id
relation
.
user2_id
=
maybeFriend
.
id
relation
.
is_blocked
=
False
session
.
add
(
relation
)
session
.
commit
()
print
(
'Relation is created in one direction only'
)
if
notification
is
True
:
print
(
'TODO Create notification'
)
return
relation
def
accept
(
self
,
username
=
None
,
notification
=
False
):
self
.
invite
(
username
=
username
,
block
=
False
,
notification
=
notification
)
def
refuse
(
self
,
username
=
None
,
notification
=
False
):
self
.
invite
(
username
=
username
,
block
=
True
,
notification
=
notification
)
def
contacts
(
self
):
"""get all contacts in one-relation with the user"""
Friend
=
aliased
(
User
)
query
=
(
session
.
query
(
Friend
)
.
join
(
Contact
,
Contact
.
user2_id
==
Friend
.
id
)
.
filter
(
Contact
.
user1_id
==
self
.
id
,
Contact
.
is_blocked
==
False
)
)
return
query
.
all
()
def
friends
(
self
):
"""get all contacts in bidirectional-relation
(both parties accepted to be linked) with the user"""
Friend
=
aliased
(
User
)
Contact1
=
aliased
(
Contact
)
Contact2
=
aliased
(
Contact
)
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
,
Contact2
.
is_blocked
==
False
)
)
return
query
.
all
()
########################################################################
def
contacts_nodes
(
self
,
typename
=
None
):
from
.nodes
import
Node
for
contact
in
self
.
contacts
():
contact_nodes
=
(
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
contact
.
id
)
.
filter
(
Node
.
typename
==
typename
)
.
order_by
(
Node
.
date
)
)
.
all
()
yield
contact
,
contact_nodes
def
owns
(
self
,
node
):
"""check if a given node is owned by the user"""
return
(
node
.
user_id
==
self
.
id
)
or
\
node
.
id
in
(
contact
.
id
for
contact
in
self
.
contacts
())
return
(
node
.
user_id
==
self
.
id
)
# def owns(self, node):
# """check if a given node is owned by the user"""
# return (node.user_id == self.id) or \
# 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.contacts():
# contact_nodes = (session
# .query(Node)
# .filter(Node.user_id == contact.id)
# .filter(Node.typename == typename)
# .order_by(Node.date)
# ).all()
# yield contact, contact_nodes
def
get_params
(
self
,
username
=
None
):
print
(
self
.
__dict__
.
items
())
return
self
.
hyperdata
class
Contact
(
Base
):
__tablename__
=
'contacts'
...
...
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