-
Notifications
You must be signed in to change notification settings - Fork 52
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 #112 from gate-sso/adding_organisations
Setting up Organisation, so that we can have seperate gate profile for every organisation
- Loading branch information
Showing
35 changed files
with
672 additions
and
737 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
--color | ||
--format documentation | ||
--require spec_helper |
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
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 |
This file was deleted.
Oops, something went wrong.
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,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 |
This file was deleted.
Oops, something went wrong.
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,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' |
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,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 |
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,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' |
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,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' |
Oops, something went wrong.