aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/policies/api_key_policy.rb3
-rw-r--r--lib/stif/permission_translator.rb3
-rw-r--r--spec/features/api_keys/edit_api_key_feature_spec.rb39
-rw-r--r--spec/features/api_keys/new_api_key_feature_spec.rb38
-rw-r--r--spec/features/line_footnotes_permissions_spec.rb2
-rw-r--r--spec/features/referential_lines_spec.rb3
-rw-r--r--spec/features/referentials_spec.rb1
7 files changed, 80 insertions, 9 deletions
diff --git a/app/policies/api_key_policy.rb b/app/policies/api_key_policy.rb
index 7b4c22e33..7c62595b5 100644
--- a/app/policies/api_key_policy.rb
+++ b/app/policies/api_key_policy.rb
@@ -14,6 +14,7 @@ class ApiKeyPolicy < ApplicationPolicy
end
def update?
- organisation_match? && user.has_permission?('api_keys.update')
+ record.try(:organisation_id) == user.organisation_id &&
+ user.has_permission?('api_keys.update')
end
end
diff --git a/lib/stif/permission_translator.rb b/lib/stif/permission_translator.rb
index d82e1c6b0..e780f4ba2 100644
--- a/lib/stif/permission_translator.rb
+++ b/lib/stif/permission_translator.rb
@@ -16,8 +16,7 @@ module Stif
def all_resources
%w[
- api_keys
- access_points
+ access_points api_keys
connection_links calendars
footnotes
journey_patterns
diff --git a/spec/features/api_keys/edit_api_key_feature_spec.rb b/spec/features/api_keys/edit_api_key_feature_spec.rb
new file mode 100644
index 000000000..411c11aaf
--- /dev/null
+++ b/spec/features/api_keys/edit_api_key_feature_spec.rb
@@ -0,0 +1,39 @@
+RSpec.describe 'New API Key', type: :feature do
+ login_user
+
+ describe "api_keys#edit" do
+
+ let!( :api_key ){ create :api_key, name: SecureRandom.uuid, organisation: @user.organisation }
+
+ let( :edit_label ){ "#{api_key.name} : #{api_key.token}" }
+ let( :name_label ){ "Nom" }
+ let( :validate_label ){ "Valider" }
+
+ let( :unique_name ){ SecureRandom.uuid }
+
+ it 'complete workflow' do
+ # /workbenches
+ visit workbenches_path
+ # api_key's new name does not exist yet
+ expect( page ).not_to have_content(unique_name)
+ # the api_key is visible
+ click_link edit_label
+
+ # brings us to correct page
+ expect(page.current_path).to eq(edit_api_key_path(api_key))
+ fill_in(name_label, with: unique_name)
+ click_button(validate_label)
+
+ # check impact on DB
+ expect(api_key.reload.name).to eq(unique_name)
+
+ # check redirect and changed display
+ expect(page.current_path).to eq(workbenches_path)
+ # changed api_key's name exists now
+ expect( page ).to have_content(unique_name)
+ end
+
+ end
+
+end
+
diff --git a/spec/features/api_keys/new_api_key_feature_spec.rb b/spec/features/api_keys/new_api_key_feature_spec.rb
new file mode 100644
index 000000000..eba873691
--- /dev/null
+++ b/spec/features/api_keys/new_api_key_feature_spec.rb
@@ -0,0 +1,38 @@
+RSpec.describe 'New API Key', type: :feature do
+ login_user
+
+ describe "api_keys#create" do
+
+ let( :create_label ){ "Créer une clé d'API" }
+ let( :name_label ){ "Nom" }
+ let( :validate_label ){ "Valider" }
+
+ let( :unique_name ){ SecureRandom.uuid }
+ let( :last_api_key ){ Api::V1::ApiKey.last }
+
+
+ it 'complete workflow' do
+ # /workbenches
+ visit workbenches_path
+ expect(page).to have_link(create_label, href: new_api_key_path)
+ # to be created api_key does not exist yet
+ expect( page ).not_to have_content(unique_name)
+
+ # /api_keys/new
+ click_link create_label
+ fill_in(name_label, with: unique_name)
+ click_button validate_label
+
+ # check impact on DB
+ expect(last_api_key.name).to eq(unique_name)
+
+ # check redirect and changed display
+ expect(page.current_path).to eq(workbenches_path)
+ # to be created api_key exists now
+ expect( page ).to have_content(unique_name)
+ end
+
+ end
+
+end
+
diff --git a/spec/features/line_footnotes_permissions_spec.rb b/spec/features/line_footnotes_permissions_spec.rb
index 4de2a6137..62adbfcd5 100644
--- a/spec/features/line_footnotes_permissions_spec.rb
+++ b/spec/features/line_footnotes_permissions_spec.rb
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
describe 'Line Footnotes', type: :feature do
login_user
diff --git a/spec/features/referential_lines_spec.rb b/spec/features/referential_lines_spec.rb
index 95fc596fd..e8cc8e0e1 100644
--- a/spec/features/referential_lines_spec.rb
+++ b/spec/features/referential_lines_spec.rb
@@ -1,6 +1,3 @@
-# -*- coding: utf-8 -*-
-require 'spec_helper'
-
describe 'ReferentialLines', type: :feature do
login_user
let!(:referential_metadata) { create :referential_metadata, referential: referential }
diff --git a/spec/features/referentials_spec.rb b/spec/features/referentials_spec.rb
index a38577aba..9af0ed32e 100644
--- a/spec/features/referentials_spec.rb
+++ b/spec/features/referentials_spec.rb
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
describe "Referentials", :type => :feature do
login_user