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

New Endpoint that 8knot needed #2134

Merged
merged 5 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
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
44 changes: 36 additions & 8 deletions augur/api/routes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def validate_user():
if checkPassword == False:
return jsonify({"status": "Invalid password"})


login_user(user)

return jsonify({"status": "Validated"})
Expand Down Expand Up @@ -436,7 +437,7 @@ def get_user_groups():

return jsonify({"status": "success", "group_names": result[0]})

@server.app.route(f"/{AUGUR_API_VERSION}/user/groups/repos/ids", methods=['GET', 'POST'])
@server.app.route(f"/{AUGUR_API_VERSION}/user/groups/repos/", methods=['GET', 'POST'])
@login_required
def get_user_groups_and_repos():
"""Get a list of user groups and their repos
Expand All @@ -450,17 +451,44 @@ def get_user_groups_and_repos():
if not development and not request.is_secure:
return generate_upgrade_request()

result = current_user.get_groups()
if not result[0]:
return result[1]
columns = request.args.get("columns")
if not columns:
return {"status": "Missing argument columns"}

# split list by , and remove whitespaces from edges

valid_columns = []
columns = columns.split(",")
for column in columns:

if column.isspace() or column == "":
continue

valid_columns.append(column.strip())

print(valid_columns)


groups = result[0]
data = []
groups = current_user.groups
for group in groups:

repo_ids = [repo.repo_id for repo in group.repos]
data.append({group.name : repo_ids})

repos = [repo.repo for repo in group.repos]

group_repo_dicts = []
for repo in repos:

repo_dict = {}
for column in valid_columns:
try:
repo_dict[column] = getattr(repo, column)
except AttributeError:
return {"status": f"'{column}' is not a valid repo column"}

group_repo_dicts.append(repo_dict)

group_data = {"repos": group_repo_dicts, "favorited": group.favorited}
data.append({group.name: group_data})

return jsonify({"status": "success", "data": data})

Expand Down
22 changes: 9 additions & 13 deletions augur/api/view/augur_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def unauthorized():

@login_manager.user_loader
def load_user(user_id):

user = User.get_user(user_id)

if not user:
Expand All @@ -79,22 +78,19 @@ def load_user_request(request):

print(f"Current time of user request: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}")
token = get_bearer_token()
print(f"Bearer token: {token}")

with DatabaseSession(logger) as session:
session = DatabaseSession(logger)

current_time = int(time.time())
token = session.query(UserSessionToken).filter(UserSessionToken.token == token, UserSessionToken.expiration >= current_time).first()
print(f"Token: {token}")
if token:
current_time = int(time.time())
token = session.query(UserSessionToken).filter(UserSessionToken.token == token, UserSessionToken.expiration >= current_time).first()
if token:

print("Valid user")
print("Valid user")

user = token.user
user._is_authenticated = True
user._is_active = True
user = token.user
user._is_authenticated = True
user._is_active = True

return user
return user

return None

Expand Down