Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/release/14.0' into dev
- Loading branch information
Showing
37 changed files
with
483 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/controllers/queries/params_parser/api_v3_filters_parser.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2010-2024 the OpenProject GmbH | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License version 3. | ||
# | ||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
# Copyright (C) 2006-2013 Jean-Philippe Lang | ||
# Copyright (C) 2010-2013 the ChiliProject Team | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# See COPYRIGHT and LICENSE files for more details. | ||
# ++ | ||
module Queries | ||
class ParamsParser | ||
class APIV3FiltersParser | ||
class << self | ||
def parse(filters_string) | ||
filters = JSON.parse(filters_string) | ||
|
||
filters.map do |filter| | ||
attribute = filter.keys.first # there should only be one attribute per filter | ||
{ | ||
attribute:, | ||
operator: filter[attribute]["operator"], | ||
values: filter[attribute]["values"] | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
117 changes: 117 additions & 0 deletions
117
app/controllers/queries/params_parser/filters_parser.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# -- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2010-2024 the OpenProject GmbH | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License version 3. | ||
# | ||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
# Copyright (C) 2006-2013 Jean-Philippe Lang | ||
# Copyright (C) 2010-2013 the ChiliProject Team | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# See COPYRIGHT and LICENSE files for more details. | ||
# ++ | ||
module Queries | ||
class ParamsParser | ||
class FiltersParser | ||
def initialize(string) | ||
@buffer = StringScanner.new(string) | ||
end | ||
|
||
def parse | ||
filters = [] | ||
|
||
while !@buffer.eos? | ||
filters << parse_filter | ||
end | ||
|
||
filters | ||
end | ||
|
||
private | ||
|
||
def parse_filter | ||
consume_ampersand | ||
|
||
{ | ||
attribute: parse_name, | ||
operator: parse_operator, | ||
values: parse_values | ||
} | ||
end | ||
|
||
def consume_ampersand | ||
case @buffer.peek(1) | ||
when "&", /\s/ | ||
@buffer.getch | ||
consume_ampersand | ||
end | ||
end | ||
|
||
def parse_name | ||
@buffer.scan_until(/\s|\z/).strip | ||
end | ||
|
||
def parse_operator | ||
@buffer.scan_until(/\s|\z/).strip | ||
end | ||
|
||
def parse_values | ||
case @buffer.peek(1) | ||
when '"' | ||
parse_doublequoted_value | ||
when "'" | ||
parse_singlequoted_value | ||
when "[" | ||
parse_array_value | ||
when "&" | ||
[] | ||
else | ||
parse_unguarded_value | ||
end | ||
end | ||
|
||
def parse_doublequoted_value | ||
@buffer.getch | ||
[@buffer.scan_until(/(?<!\\)"|\z/).delete_suffix('"').delete("\\")] | ||
end | ||
|
||
def parse_singlequoted_value | ||
@buffer.getch | ||
[@buffer.scan_until(/(?<!\\)'|\z/).delete_suffix("'").delete("\\")] | ||
end | ||
|
||
def parse_unguarded_value | ||
value = @buffer | ||
.scan_until(/&|\z/) | ||
.delete_suffix("&") | ||
|
||
[value] | ||
end | ||
|
||
def parse_array_value | ||
@buffer | ||
.scan_until(/]|\z/) | ||
.delete_suffix("]") | ||
.delete_prefix("[") | ||
.scan(/(?:'([^']*)')|(?:"([^"]*)")/) | ||
.flatten | ||
.compact | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.