Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
Display DataActivities on the security page
Browse files Browse the repository at this point in the history
  • Loading branch information
barrucadu committed Oct 22, 2020
1 parent 2966828 commit 071b750
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
12 changes: 6 additions & 6 deletions app/controllers/security_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ class SecurityController < ApplicationController
def show
@activity = current_user.security_activities.order(created_at: :desc)
@data_exchanges = current_user
.access_grants
.data_activities
.order(created_at: :desc)
.map { |g| grant_to_exchange(g) }
.map { |a| activity_to_exchange(a) }
.compact
end

private

def grant_to_exchange(grant)
scopes = grant.scopes.map(&:to_sym) - ScopeDefinition.new.hidden_scopes
def activity_to_exchange(activity)
scopes = activity.scopes.split(" ").map(&:to_sym) - ScopeDefinition.new.hidden_scopes
return if scopes.empty?

{
application_name: grant.application.name,
created_at: grant.created_at,
application_name: activity.oauth_application.name,
created_at: activity.created_at,
scopes: scopes,
}
end
Expand Down
3 changes: 3 additions & 0 deletions spec/factories/activities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
client_id { "MyString" }
ip_address { "MyString" }
end

factory :data_activity do
end
end
16 changes: 12 additions & 4 deletions spec/requests/data_exchange_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@
)
end

let!(:access_grant) do
let(:token) do
FactoryBot.create(
:oauth_access_grant,
:oauth_access_token,
resource_owner_id: user.id,
application_id: application.id,
scopes: application.scopes,
)
end

let!(:activity) do
FactoryBot.create(
:data_activity,
user_id: user.id,
oauth_application_id: application.id,
created_at: Time.zone.now,
scopes: "openid email transition_checker",
redirect_uri: "https://www.gov.uk",
expires_in: 600,
token: token.token,
)
end

Expand Down

0 comments on commit 071b750

Please sign in to comment.