Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add user filter in backend allowed values href

Oliver Günther8068c68ecd13
diff --git a/frontend/src/app/core/apiv3/helpers/add-filters-to-path.ts b/frontend/src/app/core/apiv3/helpers/add-filters-to-path.ts
new file mode 100644
index 00000000000..8c837f9c9a3
--- /dev/null
+++ b/frontend/src/app/core/apiv3/helpers/add-filters-to-path.ts
@@ -0,0 +1,35 @@
+import {
+ ApiV3Filter,
+ ApiV3FilterBuilder,
+} from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
+
+/**
+ * Add or append filters to a given base URL.
+ * If the URL already had filters, it is appending them, overriding existing filters with the same key.
+ *
+ * @param basePath The base path to add filters to.
+ * @param filters An ApiV3FilterBuilder object containing the filters to add.
+ * @param params Additional query parameters to add, if any.
+ */
+export function filteredUrl(
+ basePath:string,
+ filters:ApiV3FilterBuilder,
+ params:{ [key:string]:string } = {},
+):URL {
+ const url = new URL(basePath, window.location.origin);
+
+ if (url.searchParams.has('filters')) {
+ const existingFilters = JSON.parse(url.searchParams.get('filters') as string) as ApiV3Filter[];
+ url.searchParams.set('filters', JSON.stringify(existingFilters.concat(filters.filters)));
+ } else {
+ url.searchParams.set('filters', filters.toJson());
+ }
+
+ Object
+ .keys(params)
+ .forEach((key) => {
+ url.searchParams.set(key, params[key]);
+ });
+
+ return url;
+}
diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb
index 499ec95eac2..238aca1e926 100644
--- a/lib/api/v3/utilities/path_helper.rb
+++ b/lib/api/v3/utilities/path_helper.rb
@@ -519,6 +519,11 @@ module API
"#{project(project_id)}/work_packages"
end
+ def self.filtered_path(base_path, *filters)
+ escaped = CGI.escape(::JSON.dump(filters))
+ "#{base_path}?filters=#{escaped}"
+ end
+
def self.path_for(path, filters: nil, sort_by: nil, group_by: nil, page_size: nil, offset: nil, select: nil)
query_params = {
filters: filters&.to_json,
diff --git a/modules/costs/lib/api/v3/time_entries/schemas/time_entry_schema_representer.rb b/modules/costs/lib/api/v3/time_entries/schemas/time_entry_schema_representer.rb
index ec93ce0ef95..9798b1181a5 100644
--- a/modules/costs/lib/api/v3/time_entries/schemas/time_entry_schema_representer.rb
+++ b/modules/costs/lib/api/v3/time_entries/schemas/time_entry_schema_representer.rb
@@ -103,7 +103,9 @@ module API
end
def allowed_user_href
- api_v3_paths.available_assignees(represented.project_id)
+ base_path = api_v3_paths.available_assignees(represented.project_id)
+ api_v3_paths.filtered_path base_path,
+ type: { operator: '=', values: ['User'] }
end
end
end