-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #700 from openstax/fine-grained-app-access
Add fine grained app permissions
- Loading branch information
Showing
17 changed files
with
127 additions
and
28 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
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
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
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
24 changes: 24 additions & 0 deletions
24
db/migrate/20190911171944_add_fine_grained_access_to_oauth_applications.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,24 @@ | ||
class AddFineGrainedAccessToOauthApplications < ActiveRecord::Migration[5.2] | ||
def up | ||
add_column :oauth_applications, :can_access_private_user_data, :boolean, default: false, null: false | ||
add_column :oauth_applications, :can_find_or_create_accounts, :boolean, default: false, null: false | ||
add_column :oauth_applications, :can_message_users, :boolean, default: false, null: false | ||
add_column :oauth_applications, :can_skip_oauth_screen, :boolean, default: false, null: false | ||
|
||
Doorkeeper::Application.reset_column_information | ||
|
||
Doorkeeper::Application.where(trusted: true).update_all( | ||
can_access_private_user_data: true, | ||
can_find_or_create_accounts: true, | ||
can_message_users: true, | ||
can_skip_oauth_screen: true | ||
) | ||
end | ||
|
||
def down | ||
remove_column :oauth_applications, :can_access_private_user_data | ||
remove_column :oauth_applications, :can_find_or_create_accounts | ||
remove_column :oauth_applications, :can_message_users | ||
remove_column :oauth_applications, :can_skip_oauth_screen | ||
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
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
email_from_address: '[email protected]' | ||
} | ||
let!(:trusted_application) { | ||
FactoryBot.create :doorkeeper_application, :trusted, | ||
FactoryBot.create :doorkeeper_application, can_message_users: true, | ||
email_from_address: '[email protected]' | ||
} | ||
let!(:user_1) { FactoryBot.create :user } | ||
|
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 |
---|---|---|
|
@@ -62,6 +62,19 @@ | |
api_get :index, trusted_application_token, params: {q: 'first_name:bob last_name:Michaels'} | ||
expect(response.code).to eq('200') | ||
|
||
expected_response = { | ||
total_count: 1, | ||
items: [ user_matcher(user_2, include_private_data: false) ] | ||
} | ||
|
||
expect(response.body_as_hash).to match(expected_response) | ||
end | ||
|
||
it "returns a single result well with private data" do | ||
trusted_application.update_attribute(:can_access_private_user_data, true) | ||
api_get :index, trusted_application_token, params: {q: 'first_name:bob last_name:Michaels'} | ||
expect(response.code).to eq('200') | ||
|
||
expected_response = { | ||
total_count: 1, | ||
items: [ user_matcher(user_2, include_private_data: true) ] | ||
|
@@ -249,10 +262,16 @@ | |
end | ||
|
||
context "find or create" do | ||
let!(:foc_trusted_application) { FactoryBot.create :doorkeeper_application, can_find_or_create_accounts: true } | ||
let!(:foc_trusted_application_token) do | ||
FactoryBot.create :doorkeeper_access_token, application: foc_trusted_application, | ||
resource_owner_id: nil | ||
end | ||
|
||
it "should create a new user for an app" do | ||
expect{ | ||
api_post :find_or_create, | ||
trusted_application_token, | ||
foc_trusted_application_token, | ||
body: {email: '[email protected]', first_name: 'Ezekiel', last_name: 'Jones'} | ||
}.to change{User.count}.by(1) | ||
expect(response.code).to eq('201') | ||
|
@@ -265,7 +284,7 @@ | |
it 'creates a new user with first name, last name and full name if given' do | ||
expect { | ||
api_post :find_or_create, | ||
trusted_application_token, | ||
foc_trusted_application_token, | ||
body: { | ||
email: '[email protected]', | ||
first_name: 'Sarah', | ||
|
@@ -279,7 +298,7 @@ | |
expect(new_user.last_name).to eq 'Test' | ||
expect(new_user.full_name).to eq 'Sarah Test' | ||
expect(new_user.role).to eq 'instructor' | ||
expect(new_user.applications).to eq [ trusted_application ] | ||
expect(new_user.applications).to eq [ foc_trusted_application ] | ||
expect(new_user.uuid).not_to be_blank | ||
end | ||
|
||
|
@@ -303,7 +322,7 @@ | |
|
||
context "should return only IDs for a user" do | ||
it "does so for unclaimed users" do | ||
api_post :find_or_create, trusted_application_token, | ||
api_post :find_or_create, foc_trusted_application_token, | ||
body: {email: unclaimed_user.contact_infos.first.value} | ||
expect(response.code).to eq('201') | ||
expect(response.body_as_hash).to eq( | ||
|
@@ -314,7 +333,7 @@ | |
end | ||
it "does so for claimed users" do | ||
api_post :find_or_create, | ||
trusted_application_token, | ||
foc_trusted_application_token, | ||
body: {email: user_2.contact_infos.first.value} | ||
expect(response.code).to eq('201') | ||
expect(response.body_as_hash).to eq( | ||
|
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
describe MessagesCreate, type: :handler do | ||
|
||
let!(:trusted_application) { | ||
FactoryBot.create :doorkeeper_application, :trusted, | ||
FactoryBot.create :doorkeeper_application, can_message_users: true, | ||
email_from_address: '[email protected]' | ||
} | ||
let!(:trusted_application_token) { FactoryBot.create :doorkeeper_access_token, | ||
|
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