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 #44 from alphagov/add-supported-permissions-ui
Add a UI to add supported permissions to an application
- Loading branch information
Showing
6 changed files
with
100 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class Admin::SupportedPermissionsController < Admin::BaseController | ||
respond_to :html | ||
|
||
def index | ||
@application = ::Doorkeeper::Application.find(params[:application_id]) | ||
end | ||
|
||
def new | ||
@application = ::Doorkeeper::Application.find(params[:application_id]) | ||
end | ||
|
||
def create | ||
@application = ::Doorkeeper::Application.find(params[:application_id]) | ||
newPermission = params[:post][:permission] | ||
if newPermission.blank? | ||
redirect_to admin_application_supported_permissions_path, | ||
alert: "Failed to add permission to #{@application.name}. Field was blank." | ||
else | ||
begin | ||
SupportedPermission.create(:application_id => params[:application_id], :name => newPermission) | ||
redirect_to admin_application_supported_permissions_path, | ||
notice: "Successfully added permission #{newPermission} to #{@application.name}" | ||
rescue ActiveRecord::RecordNotUnique => exception | ||
redirect_to admin_application_supported_permissions_path, | ||
alert: "Failed to add permission #{newPermission} to #{@application.name} as it already exists" | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h1>Single Sign On Application Permissions for <%= @application.name %></h1> | ||
|
||
<div class="well"> | ||
<h3>Permissions</h3> | ||
<p id="permissions"> | ||
<%= @application.supported_permissions.map{|sp| sp.name}.join(", ") %> | ||
</p> | ||
<%= link_to "Add", new_admin_application_supported_permission_path , id: "add", class: "btn btn-primary"%> | ||
<%= link_to "Cancel", edit_admin_application_path(@application) , id: "cancel", class: "btn"%> | ||
</div> |
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,11 @@ | ||
<h1>Single Sign On Application Permissions for <%= @application.name %></h1> | ||
|
||
<div class="well"> | ||
<%= form_for @post, :as => :post, :url => admin_application_supported_permissions_path do |f| %> | ||
<p> | ||
<label for="permission">New Permission name</label> | ||
<%= f.text_field "permission" %> | ||
</p> | ||
<%= submit_tag "Save", class: "btn btn-primary" %> | ||
<% end %> | ||
</div> |
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
42 changes: 42 additions & 0 deletions
42
test/functional/admin/supported_permissions_controller_test.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,42 @@ | ||
require 'test_helper' | ||
|
||
class Admin::SupportedPermissionsControllerTest < ActionController::TestCase | ||
|
||
setup do | ||
@user = FactoryGirl.create(:user, is_admin: true) | ||
sign_in @user | ||
end | ||
|
||
context "GET index" do | ||
should "render the form" do | ||
app = FactoryGirl.create(:application, name: "My first app") | ||
perm = FactoryGirl.create(:supported_permission, application_id: app.id, name: "permission1") | ||
get :index, application_id: app.id | ||
assert_select "h1", /My first app/ | ||
assert_select "p[id='permissions']", /permission1/ | ||
assert_select "a[id='add']", true | ||
assert_select "a[id='cancel']", true | ||
end | ||
end | ||
|
||
context "GET new" do | ||
should "render the form" do | ||
app = FactoryGirl.create(:application, name: "My first app") | ||
perm = FactoryGirl.create(:supported_permission, application_id: app.id, name: "permission1") | ||
get :new, application_id: app.id | ||
assert_select "h1", /My first app/ | ||
assert_select "input[name='post[permission]']", true | ||
end | ||
end | ||
|
||
context "POST create" do | ||
should "create a new permission" do | ||
app = FactoryGirl.create(:application, name: "My first app") | ||
post :create, application_id: app.id, post:{ permission: "permission1" } | ||
assert_redirected_to(:controller => "supported_permissions", :action => :index) | ||
app.reload | ||
assert_equal app.supported_permissions.first.name, "permission1" | ||
end | ||
end | ||
|
||
end |