Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes #175

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions biblib/views/user_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,19 @@ def get_libraries(cls, service_uid, absolute_uid, start=0, rows=None, sort_col="
# The nested getattr calls allow us to request a column from the library model,
# and then request the proper sort order from that column.
with current_app.session_scope() as session:
result = session.query(Permissions, Library)\
user_libraries = session.query(Permissions, Library)\
.join(Permissions.library)\
.filter(Permissions.user_id == service_uid)\
.order_by(getattr(getattr(Library, sort_col), sort_order)())\
.all()

libraries_response = {'libraries_count': len(user_libraries)}

if rows: rows=start+rows

my_libraries = []
shared_with_me = []
for permission, library in result[start:rows]:
for permission, library in user_libraries[start:rows]:

# For this library get all the people who have permissions
users = session.query(Permissions).filter_by(
Expand Down Expand Up @@ -120,12 +122,11 @@ def get_libraries(cls, service_uid, absolute_uid, start=0, rows=None, sort_col="

if main_permission != 'owner':
# get the owner
result = session.query(Permissions, User) \
owner_permissions, owner = session.query(Permissions, User) \
.join(Permissions.user) \
.filter(Permissions.library_id == library.id) \
.filter(Permissions.permissions['owner'].astext.cast(Boolean).is_(True)) \
.one()
owner_permissions, owner = result
owner_absolute_uid = owner.absolute_uid
else:
owner_absolute_uid = absolute_uid
Expand Down Expand Up @@ -157,15 +158,13 @@ def get_libraries(cls, service_uid, absolute_uid, start=0, rows=None, sort_col="
elif ownership and main_permission in ['admin', 'read', 'write']:
shared_with_me.append(payload)


response = {'libraries_count': len(result)}
if ownership:
response['my_libraries'] = my_libraries
response['shared_with_me'] = shared_with_me
libraries_response['my_libraries'] = my_libraries
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Giving this a more descriptive name was a good idea for readability.

libraries_response['shared_with_me'] = shared_with_me
else:
response['libraries'] = my_libraries
libraries_response['libraries'] = my_libraries

return response
return libraries_response

# Methods
def get(self):
Expand All @@ -175,7 +174,7 @@ def get(self):

:param start: The index of the library list to start on (int). default: 0
:param rows: The number of rows to return from the start point (int). default: None (returns all libraries)
:param sort: Library column to sort on. default: date_created (date_created, date_last_modified)
:param sort: Library column to sort on. default: date_created (date_created, date_last_modified, name)
:param order: Direction sort libraries. default: desc (asc, desc)
:return: list of the users libraries with the relevant information

Expand Down
Loading