diff --git a/app/assets/stylesheets/shared/icons.scss b/app/assets/stylesheets/shared/icons.scss new file mode 100644 index 000000000..456e03495 --- /dev/null +++ b/app/assets/stylesheets/shared/icons.scss @@ -0,0 +1,16 @@ +@import "constants"; + +.fas-custom { + background-repeat: no-repeat; + background-size: 18px; + display: inline-block; + fill: $color-silver-chalice; + height: 18px; + position: relative; + top: 5px; + width: 18px; + + path { + fill: inherit; + } +} diff --git a/app/assets/stylesheets/themes/main_navigation.scss b/app/assets/stylesheets/themes/main_navigation.scss index 5b6ae41f8..a5f3cdb91 100644 --- a/app/assets/stylesheets/themes/main_navigation.scss +++ b/app/assets/stylesheets/themes/main_navigation.scss @@ -164,6 +164,22 @@ .repository-search { padding-left: 15px; + + .fas-custom { + fill: $brand-primary; + } + + &.active { + .fas-custom { + fill: $color-white !important; + } + } + + &.disabled { + .fas-custom { + fill: $color-silver-chalice; + } + } } } diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 1a7692053..d872897df 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,4 +1,5 @@ class SearchController < ApplicationController + include IconsHelper before_action :load_vars, only: :index def index @@ -130,9 +131,12 @@ class SearchController < ApplicationController team_results = {} team_results[:count] = 0 team_results[:repositories] = {} - team.repositories.each do |repository| + Repository.accessible_by_teams(team).each do |repository| repository_results = {} repository_results[:id] = repository.id + if (shared_repo = repository.team_repositories.where(team: team).take) + repository_results[:shared] = shared_repo[:permission_level] + end repository_results[:count] = 0 search_results.each do |result| if repository.id == result.id diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb new file mode 100644 index 000000000..e60016939 --- /dev/null +++ b/app/helpers/icons_helper.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# rubocop:disable Metrics/LineLength +module IconsHelper + def draw_custom_icon(icon) + case icon + when 'shared-edit' + icon = '' + when 'shared-read' + icon = '' + end + ('' + icon + '').html_safe + end +end +# rubocop:enable Metrics/LineLength diff --git a/app/models/repository.rb b/app/models/repository.rb index dfe1300a7..6b4cf72c6 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -41,7 +41,9 @@ class Repository < ApplicationRecord repository = nil, options = {} ) - repositories = repository || Repository.where(team: user.teams) + teams = user.teams.select(:id) + repositories = repository || + Repository.accessible_by_teams(teams) includes_json = { repository_cells: Extends::REPOSITORY_SEARCH_INCLUDES } searchable_attributes = ['repository_rows.name', 'users.full_name'] + diff --git a/app/views/search/index.html.erb b/app/views/search/index.html.erb index 790b6c573..1c39707e1 100644 --- a/app/views/search/index.html.erb +++ b/app/views/search/index.html.erb @@ -233,6 +233,11 @@ search_id: @search_id}.to_query %>"> <%= values[:count] %> <%= repository %> + <% if values[:shared] == 'write' %> + <%= draw_custom_icon('shared-edit') %> + <% elsif values[:shared] == 'read' %> + <%= draw_custom_icon('shared-read') %> + <% end %> <% end %>