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
2f68aa2a
Commit
2f68aa2a
authored
Mar 27, 2017
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT COLLABORATIVE] Fix.
parent
30c7569c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
12 deletions
+31
-12
users.py
gargantext/models/users.py
+31
-12
No files found.
gargantext/models/users.py
View file @
2f68aa2a
...
...
@@ -41,7 +41,7 @@ class User(Base):
return
query
def
invite
(
self
,
username
=
None
,
block
=
False
,
notification
=
True
):
def
invite
s
(
self
,
username
=
None
,
block
=
False
,
notification
=
True
):
if
username
is
None
:
raise
ValueError
(
'if you contact someone give his username please.'
)
...
...
@@ -55,8 +55,8 @@ class User(Base):
relation
=
(
session
.
query
(
Contact
)
.
filter
(
user1_id
==
self
.
id
,
user2_id
==
maybeFriend
.
id
.
filter
(
Contact
.
user1_id
==
self
.
id
,
Contact
.
user2_id
==
maybeFriend
.
id
)
.
first
()
)
...
...
@@ -84,25 +84,27 @@ class User(Base):
return
relation
def
accept
(
self
,
username
=
None
,
notification
=
False
):
self
.
invite
(
username
=
username
,
block
=
False
,
notification
=
notification
)
def
accept
s
(
self
,
username
=
None
,
notification
=
False
):
self
.
invite
s
(
username
=
username
,
block
=
False
,
notification
=
notification
)
def
refuse
(
self
,
username
=
None
,
notification
=
False
):
self
.
invite
(
username
=
username
,
block
=
True
,
notification
=
notification
)
def
refuse
s
(
self
,
username
=
None
,
notification
=
False
):
self
.
invite
s
(
username
=
username
,
block
=
True
,
notification
=
notification
)
def
contacts
(
self
):
"""get all contacts in one-relation with the user"""
Friend
=
aliased
(
User
)
""" Get all contacts in one-relation with the user"""
MaybeFriend
=
aliased
(
User
)
query
=
(
session
.
query
(
Friend
)
.
join
(
Contact
,
Contact
.
user2_id
==
Friend
.
id
)
.
query
(
Maybe
Friend
)
.
join
(
Contact
,
Contact
.
user2_id
==
Maybe
Friend
.
id
)
.
filter
(
Contact
.
user1_id
==
self
.
id
,
Contact
.
is_blocked
==
False
)
)
return
query
.
all
()
def
friends
(
self
):
"""
g
et all contacts in bidirectional-relation
"""
G
et all contacts in bidirectional-relation
(both parties accepted to be linked) with the user"""
Friend
=
aliased
(
User
)
...
...
@@ -118,6 +120,23 @@ class User(Base):
)
return
query
.
all
()
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
()
########################################################################
...
...
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