Skip to content

Commit

Permalink
Adjust api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Nov 21, 2023
1 parent dca39be commit c6648fb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 50 deletions.
37 changes: 3 additions & 34 deletions client/src/api/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1485,13 +1485,9 @@ export interface paths {
/** Remove the object from user's favorites */
delete: operations["remove_favorite_api_users__user_id__favorites__object_type___object_id__delete"];
};
"/api/users/{user_id}/impersonate": {
/** Impersonates a user. Only admins can impersonate users. */
post: operations["impersonate_user_api_users__user_id__impersonate_post"];
};
"/api/users/{user_id}/recalculate_disk_usage": {
"/api/users/{user_id}/recalculate": {
/** Triggers a recalculation of the current user disk usage. */
put: operations["recalculate_disk_usage_by_user_id_api_users__user_id__recalculate_disk_usage_put"];
put: operations["recalculate_disk_usage_by_user_id_api_users__user_id__recalculate_put"];
};
"/api/users/{user_id}/send_activation_email": {
/** Sends activation email to user. */
Expand Down Expand Up @@ -17850,34 +17846,7 @@ export interface operations {
};
};
};
impersonate_user_api_users__user_id__impersonate_post: {
/** Impersonates a user. Only admins can impersonate users. */
parameters: {
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
header?: {
"run-as"?: string;
};
/** @description The ID of the user to get. */
path: {
user_id: string;
};
};
responses: {
/** @description Successful Response */
200: {
content: {
"application/json": Record<string, never>;
};
};
/** @description Validation Error */
422: {
content: {
"application/json": components["schemas"]["HTTPValidationError"];
};
};
};
};
recalculate_disk_usage_by_user_id_api_users__user_id__recalculate_disk_usage_put: {
recalculate_disk_usage_by_user_id_api_users__user_id__recalculate_put: {
/** Triggers a recalculation of the current user disk usage. */
parameters: {
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
Expand Down
1 change: 0 additions & 1 deletion client/src/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { fetcher } from "@/api/schema";
export const createApiKey = fetcher.path("/api/users/{user_id}/api_key").method("post").create();
export const deleteUser = fetcher.path("/api/users/{user_id}").method("delete").create();
export const fetchQuotaUsages = fetcher.path("/api/users/{user_id}/usage").method("get").create();
export const impersonateUser = fetcher.path("/api/users/{user_id}/impersonate").method("post").create();
export const recalculateDiskUsage = fetcher.path("/api/users/current/recalculate_disk_usage").method("put").create();
export const recalculateDiskUsageByUserId = fetcher
.path("/api/users/{user_id}/recalculate_disk_usage")
Expand Down
24 changes: 12 additions & 12 deletions client/src/components/Grid/configs/adminUsers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";
import type Router from "vue-router";

import { createApiKey, deleteUser, impersonateUser, recalculateDiskUsageByUserId, sendActivationEmail, undeleteUser, updateUser } from "@/api/users";
import { createApiKey, deleteUser, recalculateDiskUsageByUserId, sendActivationEmail, undeleteUser, updateUser } from "@/api/users";
import type { ConfigType } from "@/composables/config";
import Filtering, { contains, equals, toBool, type ValidFilter } from "@/utils/filtering";
import { withPrefix } from "@/utils/redirect";
Expand Down Expand Up @@ -134,6 +134,16 @@ const fields = [
}
},
},
{
title: "Impersonate User",
icon: "user",
condition: (data: UserEntry, config: ConfigType) => {
return config.value.allow_user_impersonation && !data.deleted;
},
handler: async (data: UserEntry) => {
window.location.href = withPrefix(`/admin/impersonate?id=${String(data.id)}`);
},
},
{
title: "Delete",
icon: "trash",
Expand Down Expand Up @@ -197,16 +207,6 @@ const fields = [
}
},
},
{
title: "Impersonate User",
icon: "user",
condition: (data: UserEntry, config: ConfigType) => {
return config.value.allow_user_impersonation && !data.deleted;
},
handler: async (data: UserEntry, router: Router) => {
window.location.href = withPrefix(`/admin/impersonate?id=${data.id}`);
},
},
{
title: "Activate",
icon: "user",
Expand Down Expand Up @@ -308,6 +308,6 @@ export default {
plural: "Users",
sortBy: "email",
sortDesc: true,
sortKeys: ["activated", "create_time", "disk_usage", "email", "external", "last_login", "status", "username"],
sortKeys: ["active", "create_time", "disk_usage", "email", "external", "last_login", "status", "username"],
title: "Users",
};
2 changes: 1 addition & 1 deletion lib/galaxy/web/framework/helpers/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def __call__(self, trans, **kwargs):

# Build initial query
query = self.build_initial_query(trans, **kwargs)
query = self.apply_query_filter(trans, query, **kwargs)
query = self.apply_query_filter(query, **kwargs)

# Process sort arguments.
sort_by = kwargs.get("sort_by", self.default_sort_key)
Expand Down
2 changes: 2 additions & 0 deletions lib/galaxy/webapps/galaxy/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def recalculate_disk_usage(
"/api/users/{user_id}/recalculate_disk_usage",
summary=RecalculateDiskUsageSummary,
responses=RecalculateDiskUsageResponseDescriptions,
require_admin=True,
)
def recalculate_disk_usage_by_user_id(
self,
Expand Down Expand Up @@ -695,6 +696,7 @@ def delete(

@router.post(
"/api/users/{user_id}/send_activation_email",
name="send_activation_email",
summary="Sends activation email to user.",
)
def send_activation_email(
Expand Down
6 changes: 4 additions & 2 deletions lib/galaxy/webapps/galaxy/controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,16 @@ def sort(self, trans, query, ascending, column_name=None):
grids.PurgedColumn("Purged", key="purged"),
]

def apply_query_filter(self, trans, query, **kwargs):
def apply_query_filter(self, query, **kwargs):
INDEX_SEARCH_FILTERS = {
"email": "email",
"username": "username",
"is": "is",
}
search_query = kwargs.get("search")
if search_query:
if search_query is None:
query = query.filter(self.model_class.deleted == false())
else:
parsed_search = parse_filters_structured(search_query, INDEX_SEARCH_FILTERS)
for term in parsed_search.terms:
if isinstance(term, FilteredTerm):
Expand Down

0 comments on commit c6648fb

Please sign in to comment.