diff --git a/Gemfile.lock b/Gemfile.lock index 63d3ab67f..449677344 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -301,7 +301,7 @@ GEM js_cookie_rails (2.2.0) railties (>= 3.1) json (1.8.6) - json-jwt (1.10.2) + json-jwt (1.11.0) activesupport (>= 4.2) aes_key_wrap bindata @@ -346,7 +346,7 @@ GEM mini_magick (4.9.5) mini_mime (1.0.2) mini_portile2 (2.4.0) - minitest (5.11.3) + minitest (5.13.0) momentjs-rails (2.17.1) railties (>= 3.1) msgpack (1.3.1) @@ -590,7 +590,7 @@ GEM wkhtmltopdf-heroku (2.12.5.0) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.1.10) + zeitwerk (2.2.1) PLATFORMS ruby diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 52b81f169..a7e952991 100644 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -80,7 +80,7 @@ module Api end # Default token implementation - unless iss == Api.configuration.core_api_token_iss + unless iss == Rails.configuration.x.core_api_token_iss raise JWT::InvalidPayload, I18n.t('api.core.wrong_iss') end payload = CoreJwt.decode(token) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 376607973..212b23aca 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -28,7 +28,11 @@ class RepositoriesController < ApplicationController render 'repositories/index' end - def show; end + def show + @display_edit_button = can_create_repository_rows?(@repository) + @display_delete_button = can_delete_repository_rows?(@repository) + @display_duplicate_button = can_create_repository_rows?(@repository) + end def create_modal @repository = Repository.new diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index 6c6dc6944..ffab95602 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -12,8 +12,9 @@ class RepositoryRowsController < ApplicationController copy_records available_rows) before_action :check_create_permissions, only: :create + before_action :check_delete_permissions, only: :delete_records before_action :check_manage_permissions, - only: %i(edit update delete_records copy_records) + only: %i(edit update copy_records) def index @draw = params[:draw].to_i @@ -372,6 +373,10 @@ class RepositoryRowsController < ApplicationController render_403 unless can_manage_repository_rows?(@repository) end + def check_delete_permissions + render_403 unless can_delete_repository_rows?(@repository) + end + def record_params params.permit(:repository_row_name).to_h end diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 3c2b0af94..a52c97e8e 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -1,4 +1,8 @@ +# frozen_string_literal: true + class Users::SessionsController < Devise::SessionsController + layout :session_layout + # before_filter :configure_sign_in_params, only: [:create] after_action :after_sign_in, only: :create @@ -8,6 +12,7 @@ class Users::SessionsController < Devise::SessionsController # GET /resource/sign_in def new + @simple_sign_in = params[:simple_sign_in] == 'true' # If user was redirected here from OAuth's authorize/new page (Doorkeeper # endpoint for authorizing an OAuth client), 3rd party sign-in buttons # (e.g. LinkedIn) should be hidden. See config/initializers/devise.rb. @@ -76,4 +81,14 @@ class Users::SessionsController < Devise::SessionsController def configure_sign_in_params devise_parameter_sanitizer.for(:sign_in) << :attribute end + + private + + def session_layout + if @simple_sign_in + 'sign_in_halt' + else + 'layouts/main' + end + end end diff --git a/app/controllers/users/settings/account/connected_accounts_controller.rb b/app/controllers/users/settings/account/connected_accounts_controller.rb new file mode 100644 index 000000000..2edee3954 --- /dev/null +++ b/app/controllers/users/settings/account/connected_accounts_controller.rb @@ -0,0 +1,19 @@ +module Users + module Settings + module Account + class ConnectedAccountsController < ApplicationController + layout 'fluid' + + def index + @linked_accounts = current_user.user_identities.pluck(:provider) + end + + def destroy + current_user.user_identities.where(provider: params.require(:provider)).take&.destroy! + @linked_accounts = current_user.user_identities.pluck(:provider) + render :index + end + end + end + end +end diff --git a/app/helpers/left_menu_bar_helper.rb b/app/helpers/left_menu_bar_helper.rb index 13c0260d8..536ef7391 100644 --- a/app/helpers/left_menu_bar_helper.rb +++ b/app/helpers/left_menu_bar_helper.rb @@ -18,7 +18,7 @@ module LeftMenuBarHelper end def settings_are_selected? - controller_name.in? %(registrations preferences addons teams) + controller_name.in? %(registrations preferences addons teams connected_accounts) end def activities_are_selected? diff --git a/app/helpers/user_settings_helper.rb b/app/helpers/user_settings_helper.rb index 448ef9b63..3332564e0 100644 --- a/app/helpers/user_settings_helper.rb +++ b/app/helpers/user_settings_helper.rb @@ -2,7 +2,8 @@ module UserSettingsHelper def on_settings_account_page? controller_name == 'registrations' && action_name == 'edit' || controller_name == 'preferences' && action_name == 'index' || - controller_name == 'addons' && action_name == 'index' + controller_name == 'addons' && action_name == 'index' || + controller_name == 'connected_accounts' end def on_settings_account_profile_page? @@ -21,4 +22,8 @@ module UserSettingsHelper controller_name.in?(%w(teams audits)) && action_name.in?(%w(index new create show audits_index)) end + + def on_settings_account_connected_accounts_page? + controller_name == 'connected_accounts' + end end diff --git a/app/models/user.rb b/app/models/user.rb index 973f6415d..149fe3a52 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -486,7 +486,7 @@ class User < ApplicationRecord includes(:user_identities) .where( 'user_identities.provider=? AND user_identities.uid=?', - Api.configuration.azure_ad_apps[token_payload[:aud]][:provider], + Rails.configuration.x.azure_ad_apps[token_payload[:aud]][:provider], token_payload[:sub] ) .references(:user_identities) diff --git a/app/permissions/repository.rb b/app/permissions/repository.rb index 05e018c89..47b78d9c8 100644 --- a/app/permissions/repository.rb +++ b/app/permissions/repository.rb @@ -30,6 +30,14 @@ Canaid::Permissions.register_for(Repository) do can_create_repository_rows?(user, repository) end + can :update_repository_rows do |user, repository| + can_manage_repository_rows?(user, repository) + end + + can :delete_repository_rows do |user, repository| + can_manage_repository_rows?(user, repository) + end + # repository: create field can :create_repository_columns do |user, repository| can_create_repository_rows?(user, repository) unless repository.shared_with?(user.current_team) diff --git a/app/services/api.rb b/app/services/api.rb deleted file mode 100644 index 322d01e26..000000000 --- a/app/services/api.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Api - class << self - attr_accessor :configuration - end - - def self.configuration - @configuration ||= Configuration.new - end - - def self.configure - yield(configuration) - end - - class Configuration - attr_accessor :core_api_sign_alg - attr_accessor :core_api_token_ttl - attr_accessor :core_api_token_iss - attr_accessor :azure_ad_apps - attr_accessor :core_api_v1_enabled - attr_accessor :core_api_rate_limit - - def initialize - @core_api_sign_alg = 'HS256' - @core_api_token_ttl = 30.minutes - @core_api_token_iss = 'SciNote' - @azure_ad_apps = {} - @core_api_v1_enabled = false - @core_api_rate_limit = 1000 - end - end -end diff --git a/app/services/api/azure_jwt.rb b/app/services/api/azure_jwt.rb index 4df270651..f6804d2ce 100644 --- a/app/services/api/azure_jwt.rb +++ b/app/services/api/azure_jwt.rb @@ -9,7 +9,7 @@ module Api def self.fetch_rsa_key(k_id, app_id) cache_key = "api_azure_ad_rsa_key_#{k_id}" Rails.cache.fetch(cache_key, expires_in: KEYS_CACHING_PERIOD) do - conf_url = Api.configuration.azure_ad_apps[app_id][:conf_url] + conf_url = Rails.configuration.x.azure_ad_apps[app_id][:conf_url] keys_url = JSON.parse(Net::HTTP.get(URI(conf_url)))['jwks_uri'] data = JSON.parse(Net::HTTP.get(URI.parse(keys_url))) verif_key = data['keys'].find { |key| key['kid'] == k_id } @@ -35,7 +35,7 @@ module Api # Now search for matching app variables in configuration app_id = unverified_token[0]['aud'] - app_config = Api.configuration.azure_ad_apps[app_id] + app_config = Rails.configuration.x.azure_ad_apps[app_id] unless app_config raise JWT::VerificationError, 'Azure AD: No application configured with such ID' diff --git a/app/services/api/core_jwt.rb b/app/services/api/core_jwt.rb index 10c39850a..14b0b2795 100644 --- a/app/services/api/core_jwt.rb +++ b/app/services/api/core_jwt.rb @@ -7,15 +7,15 @@ module Api if expires_at payload[:exp] = expires_at else - payload[:exp] = Api.configuration.core_api_token_ttl.from_now.to_i + payload[:exp] = Rails.configuration.x.core_api_token_ttl.from_now.to_i end - payload[:iss] = Api.configuration.core_api_token_iss - JWT.encode(payload, KEY_SECRET, Api.configuration.core_api_sign_alg) + payload[:iss] = Rails.configuration.x.core_api_token_iss + JWT.encode(payload, KEY_SECRET, Rails.configuration.x.core_api_sign_alg) end def self.decode(token) HashWithIndifferentAccess.new( - JWT.decode(token, KEY_SECRET, Api.configuration.core_api_sign_alg)[0] + JWT.decode(token, KEY_SECRET, Rails.configuration.x.core_api_sign_alg)[0] ) end diff --git a/app/views/layouts/sign_in_halt.html.erb b/app/views/layouts/sign_in_halt.html.erb index b9a4f43b7..0e799efb2 100644 --- a/app/views/layouts/sign_in_halt.html.erb +++ b/app/views/layouts/sign_in_halt.html.erb @@ -27,11 +27,13 @@ <%= image_tag('/images/scinote_icon.jpg', id: 'logo') %> -
+ <% if user_signed_in? %> + + <% end %> <% if flash[:error]%> diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index ef664aeb2..6a931cd9b 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -128,21 +128,29 @@ <% end %> <% if can_manage_repository_rows?(@repository) %> - - - + + <%if @display_edit_button %> + + <% end %> + + <%if @display_delete_button %> + + <% end %> + + <%if @display_duplicate_button %> + + <%end%> <% elsif @repository.shared_with?(current_team) %><%= t('repositories.index.view_only_permission_label') %>
<% end %> diff --git a/app/views/users/sessions/new.html.erb b/app/views/users/sessions/new.html.erb index 9f87fcf33..245e51f83 100644 --- a/app/views/users/sessions/new.html.erb +++ b/app/views/users/sessions/new.html.erb @@ -18,17 +18,19 @@ <%= f.password_field :password, autocomplete: "off", class: "form-control", placeholder: t("devise.sessions.new.password_placeholder") %> - <% if devise_mapping.rememberable? -%> + <% if devise_mapping.rememberable? && !@simple_sign_in %><%= t('users.settings.account.connected_accounts.azure_ad.connect_hint') %>
+