mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
* DynamicComponent for QuerySourceAlerts * General Settings updates * Dynamic Date[Range] updates * EmptyState updates * Query and SchemaBrowser updates * Adjust page headers and add disablePublish * Policy updates * Separate Home FavoritesList component * Update FormatQuery * Autolimit frontend fixes * Misc updates * Keep registering of QuerySourceDropdown * Undo changes in DynamicComponent * Change sql-formatter package.json syntax * Allow opening help trigger in new tab * Don't run npm commands as root in Dockerfile * Cypress: Remove extra execute query
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
import { isNil, isEmpty } from "lodash";
|
|
import { useMemo } from "react";
|
|
import { currentUser } from "@/services/auth";
|
|
import { policy } from "@/services/policy";
|
|
|
|
export default function useQueryFlags(query, dataSource = null) {
|
|
dataSource = dataSource || { view_only: true };
|
|
|
|
return useMemo(
|
|
() => ({
|
|
// state flags
|
|
isNew: isNil(query.id),
|
|
isDraft: query.is_draft,
|
|
isArchived: query.is_archived,
|
|
|
|
// permissions flags
|
|
canCreate: currentUser.hasPermission("create_query"),
|
|
canView: currentUser.hasPermission("view_query"),
|
|
canEdit: currentUser.hasPermission("edit_query") && policy.canEdit(query),
|
|
canViewSource: currentUser.hasPermission("view_source"),
|
|
canExecute:
|
|
!isEmpty(query.query) &&
|
|
policy.canRun(query) &&
|
|
(query.is_safe || (currentUser.hasPermission("execute_query") && !dataSource.view_only)),
|
|
canFork: currentUser.hasPermission("edit_query") && !dataSource.view_only,
|
|
canSchedule: currentUser.hasPermission("schedule_query"),
|
|
}),
|
|
[query, dataSource.view_only]
|
|
);
|
|
}
|