noshutdown-ru / vault

Is a plugin for project management system Redmine. Allows you to store various passwords/keys in one place for the project.
https://noshutdown.ru/en/redmine-plugins-vault
46 stars 29 forks source link

Search by any field #64

Open Luckyvb opened 4 years ago

Luckyvb commented 4 years ago

Add search type any and set by default.

Luckyvb commented 4 years ago

diff --git a/app/controllers/keys_controller.rb b/app/controllers/keys_controller.rb index 970e0da..c254709 100644 --- a/app/controllers/keys_controller.rb +++ b/app/controllers/keys_controller.rb @@ -27,7 +27,7 @@ class KeysController < ApplicationController @query = params[:query]

if params[:search_fild] == nila - @search_fild = 'name' + @search_fild = 'any' else @search_fild = params[:search_fild] end @@ -38,10 +38,14 @@ class KeysController < ApplicationController tag = Vault::Tag.find_by_name(tag_string) @keys = tag.nil? ? nil : tag.keys.where(project: @project) else - if params[:search_fild] == 'name' - @keys = @project.keys.where(name: @query) + if params[:search_fild] == 'any' + @keys = @project.keys.where("name LIKE ? or login LIKE ?", "%"+@query+"%", "%"+@query+"%").or(@project.keys.where("url LIKE ?", "%"+@query+"%")) + tag = Vault::Tag.find_by_name(@query) + @keys.union(tag.keys.where(project: @project)) if !tag.nil? + elsif params[:search_fild] == 'name' + @keys = @project.keys.where("name LIKE ? or login LIKE ?", "%"+@query+"%", "%"+@query+"%") elsif params[:search_fild] == 'url' - @keys = @project.keys.where(url: @query) + @keys = @project.keys.where("url LIKE ?", "%"+@query+"%") elsif params[:search_fild] == 'tag' tag = Vault::Tag.find_by_name(@query) @keys = tag.nil? ? nil : tag.keys.where(project: @project)

diff --git a/app/views/keys/index.html.erb b/app/views/keys/index.html.erb index 0c2c521..dd4e1f2 100644 --- a/app/views/keys/index.html.erb +++ b/app/views/keys/index.html.erb @@ -14,6 +14,9 @@ <%= text_field_tag(:query, @query, class: 'autocomplete') %>

<font size="2"> + <%= radio_button_tag(:search_fild, "any", @search_fild == 'any' ? true : false ) %> + <%= label_tag(:any, t('key.attr.any')) %> + <%= radio_button_tag(:search_fild, "name", @search_fild == 'name' ? true : false ) %> <%= label_tag(:name, t('key.attr.name')) %>

diff --git a/config/locales/ru.yml b/config/locales/ru.yml index bd41238..2f6fe95 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -53,6 +60,7 @@ ru: file: "Файл ключа" comment: "Комментарий" whitelist: "Список доступа" + any: "Любое"

whitelist: selected_members: "Выбранные участники"

noshutdown-ru-user commented 4 years ago

Thx for report, we will take a look