Skip to content

Commit

Permalink
Merge pull request #112 from gate-sso/adding_organisations
Browse files Browse the repository at this point in the history
Setting up Organisation, so that we can have seperate gate profile for every organisation
  • Loading branch information
ajeygore authored Jun 14, 2018
2 parents 61550a4 + d241486 commit 55c309f
Show file tree
Hide file tree
Showing 35 changed files with 672 additions and 737 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--color
--format documentation
--require spec_helper
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ Style/StringLiterals:
Style/TrailingCommaInArguments:
Description: 'Checks for trailing comma in argument lists.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
EnforcedStyleForMultiline: comma
EnforcedStyleForMultiline: no_comma
SupportedStylesForMultiline:
- comma
- consistent_comma
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ gem 'puma'
gem 'rails', '4.2.8'
gem 'redis'
gem 'rotp'
gem 'saml_idp', git: 'https://github.com/gate-sso/saml_idp.git'
gem 'sass-rails'
gem 'sdoc', group: :doc
gem 'slim-rails'
Expand Down
16 changes: 0 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
GIT
remote: https://github.com/gate-sso/saml_idp.git
revision: cd646cbb9baf9af05df87af33d5368c74713f46c
specs:
saml_idp (0.7.2)
activesupport (>= 3.2)
builder (>= 3.0)
nokogiri (>= 1.6.2)
uuid (>= 2.3)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -130,8 +120,6 @@ GEM
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
macaddr (1.7.1)
systemu (~> 2.6.2)
mail (2.7.0)
mini_mime (>= 0.1.1)
method_source (0.9.0)
Expand Down Expand Up @@ -291,7 +279,6 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
systemu (2.6.5)
temple (0.8.0)
term-ansicolor (1.2.2)
tins (~> 0.8)
Expand All @@ -308,8 +295,6 @@ GEM
uglifier (4.1.11)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.4.0)
uuid (2.3.9)
macaddr (~> 1.0)
warden (1.2.7)
rack (>= 1.0)
web-console (3.3.0)
Expand Down Expand Up @@ -355,7 +340,6 @@ DEPENDENCIES
rspec-rails
rubocop
rubocop-rspec
saml_idp!
sass-rails
sdoc
shoulda-matchers
Expand Down
6 changes: 4 additions & 2 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
* https://github.com/ladjs/bootstrap-social
*/
@import "bootstrap-social";

a.btn { color: white!important; }
.form-group .field_with_errors { display: block; background: none; }
.form-group .field_with_errors label::after { content: ' *'; color: red; }
body {
font-family: 'Roboto', 'Lato', sans-serif;
}
Expand All @@ -36,7 +38,7 @@ body {
min-width: 768px;
}

a:visited {
a:visited {
color: blue;
}
/* mouse over link */
Expand Down
48 changes: 48 additions & 0 deletions app/controllers/organisations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class OrganisationsController < ApplicationController
def index
render :index, locals: { org_list: Organisation.all }
end

def new
render :new, locals: { org: Organisation.new }
end

def create
org = Organisation.setup(organisation_params.to_h || {})
if org.errors.blank?
flash[:success] = 'Successfully created organisation'
redirect_to organisations_path
else
flash[:errors] = org.errors.full_messages
redirect_to new_organisation_path
end
end

def update
org = load_org
org.update_profile(organisation_params.to_h || {})
if org.errors.blank?
flash[:success] = 'Successfully updated organisation'
redirect_to organisations_path
else
flash[:errors] = org.errors.full_messages
redirect_to organisation_path(org)
end
end

def show
render :show, locals: { org: load_org }
end

private

def load_org
org = Organisation.where(params[:id]).first
redirect_to organisations_path if org.blank?
org
end

def organisation_params
params.require(:organisation).permit(:name, :url, :email_domain)
end
end
99 changes: 0 additions & 99 deletions app/controllers/saml_idp_controller.rb

This file was deleted.

18 changes: 18 additions & 0 deletions app/models/organisation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Organisation < ActiveRecord::Base
validates :name, :url, :email_domain, presence: true

def self.setup(attrs = {})
attrs.stringify_keys!
attrs = attrs.select { |k, _v| %w(name url email_domain).include?(k) }
org = Organisation.new(attrs)
org.save if org.valid?
org
end

def update_profile(attrs = {})
attrs.stringify_keys!
attrs = attrs.select { |k, _v| %w(name url email_domain).include?(k) }
assign_attributes(attrs)
save if valid?
end
end
2 changes: 0 additions & 2 deletions app/models/saml_service_provider.rb

This file was deleted.

29 changes: 15 additions & 14 deletions app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,32 @@ html lang="en"
/! Fixed navbar
nav.navbar.navbar-expand-md.navbar-dark.fixed-top.bg-dark
a.navbar-brand href="/profile" gate
button.navbar-toggler aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label=("Toggle navigation") data-target="#navbarsExampleDefault" data-toggle="collapse" type="button"
button.navbar-toggler aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label=("Toggle navigation") data-target="#main-navigation" data-toggle="collapse" type="button"
span.navbar-toggler-icon
#navbarsExampleDefault.collapse.navbar-collapse
#main-navigation.collapse.navbar-collapse
ul.navbar-nav.mr-auto
li#user-index.nav-item
- if current_user.admin?
= link_to("Users", users_path, class: "nav-link")
li#group-index.nav-item
- if current_user.admin? || current_user.group_admin?
= link_to "Groups", groups_path, class: "nav-link"
li#hostmachine-index.nav-item
- if current_user.admin?
= link_to "Hosts", host_machines_path, class: "nav-link"
- if current_user.admin?
li#user-index.nav-item
= link_to("Users", users_path, class: "nav-link")
li#hostmachine-index.nav-item
= link_to "Hosts", host_machines_path, class: "nav-link"
li#organisation-index.nav-item
= link_to "Organisations", organisations_path, class: "nav-link"
- if current_user.admin? || current_user.group_admin?
li#group-index.nav-item
= link_to "Groups", groups_path, class: "nav-link"
li#apiresource-index.nav-item
= link_to "APIs", api_resources_path, class: "nav-link"
li#vpn-index.nav-item
= link_to "VPNs", vpns_path, class: "nav-link"
li.nav-item.dropdown
a#dropdown01.nav-link.dropdown-toggle aria-expanded="false" aria-haspopup="true" data-toggle="dropdown" href="http://example.com" New
.dropdown-menu aria-labelledby="dropdown01"
.dropdown-menu aria-labelledby="dropdown01"
= link_to "API", new_api_resource_path, class: "dropdown-item"
- if current_user.admin?
- if current_user.admin?
= link_to "Group", new_group_path, class: "dropdown-item"
= link_to "VPN", new_vpn_path, class: "dropdown-item"

= link_to "Organisation", new_organisation_path, class: "dropdown-item"
ul.nav.navbar-nav.navbar-right
li.nav-link
= link_to "Sign out", users_sign_out_path,:method => :delete , class: "nav-link"
Expand Down
16 changes: 16 additions & 0 deletions app/views/organisations/_form.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- if flash.key?(:errors)
.alert.alert-danger#organisation_form_errors
b Issue creating application
br
- flash[:errors].each do |msg|
= "- #{msg}"
br
.form-group
= f.label :name
= f.text_field :name, class: 'form-control'
.form-group
= f.label :url
= f.text_field :url, class: 'form-control'
.form-group
= f.label :email_domain
= f.text_field :email_domain, class: 'form-control'
26 changes: 26 additions & 0 deletions app/views/organisations/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.container.col-md-8
.row.mb-3.mt-2
.col-md-8
h5 Organisations
.col-md-4.text-right
= link_to "New Organisation", new_organisation_path, class: "btn btn-primary", id: 'new_organisation_btn'
- if flash.key?(:success)
.alert.alert-success#organisation_form_success
= flash[:success]
#organisation_list.table-responsive
table.table.table-striped
thead
tr
th Name
th URL
th Email Domain
tbody
- if org_list.present?
- org_list.each do |org|
tr
td = link_to org.name, organisation_path(org)
td = link_to org.url, org.url
td = org.email_domain
- else
td.text-center colspan='3'
p There are no organisations yet, why don't you create an organisation
8 changes: 8 additions & 0 deletions app/views/organisations/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.container.col-md-8
.row.mb-3.mt-2
.col-md-12
h5 Create Organisation
hr
= form_for(org) do |f|
= render partial: 'form', locals: {f: f}
= f.submit 'Create Organisation', class: 'btn btn-primary mb-2'
8 changes: 8 additions & 0 deletions app/views/organisations/show.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.container.col-md-8
.row.mb-3.mt-2
.col-md-12
h5 Update Organisation
hr
= form_for(org) do |f|
= render partial: 'form', locals: {f: f}
= f.submit 'Update Organisation', class: 'btn btn-primary mb-2'
Loading

0 comments on commit 55c309f

Please sign in to comment.