Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Bushido bootstrap and hooks. Readies the app for non-Bushido pla…
…tforms. Signed-off-by: Akash Manohar J <akash@akash.im>
- Loading branch information
Showing
11 changed files
with
153 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div class="widget" id="widget_<%= @element_id %>"> | ||
<div class="widget_header"> | ||
<h3 style="background-image:url(<%= @icon_url %>);"><%= @title %></h3> | ||
</div> | ||
<div class="widget_content" id="<%= @element_id %>"></div> | ||
<div class="widget_action_bar"></div> | ||
</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
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 |
---|---|---|
@@ -1,6 +1,16 @@ | ||
require "#{Rails.root}/lib/kandan_config.rb" | ||
|
||
Dir["#{Rails.root}/lib/broadcasters/**/*.rb"].each do |file| | ||
require file | ||
end | ||
|
||
require "#{Rails.root}/lib/kandan_config.rb" | ||
|
||
module Kandan | ||
def self.devise_modules | ||
standard = [:database_authenticatable, :registerable, :confirmable, | ||
:recoverable, :rememberable, :trackable, :validatable] | ||
bushido = [:bushido_authenticatable, :trackable, :token_authenticatable] | ||
|
||
::Bushido::Platform.on_bushido? ? bushido : standard | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddActiveToUsers < ActiveRecord::Migration | ||
def change | ||
add_column :users, :active, :boolean, :default => true | ||
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,43 @@ | ||
module Kandan | ||
module Bushido | ||
def self.enable_bushido! | ||
self.load_hooks! | ||
self.extend_user! | ||
self.extend_project! | ||
end | ||
|
||
def self.extend_user! | ||
puts "Extending the User model" | ||
User.instance_eval do | ||
validates_presence_of :ido_id | ||
validates_uniqueness_of :ido_id | ||
|
||
attr_accessible :ido_id | ||
end | ||
|
||
User.class_eval do | ||
def bushido_extra_attributes(extra_attributes) | ||
self.first_name = "#{extra_attributes['first_name']}" | ||
self.last_name = "#{extra_attributes['last_name']}" | ||
self.locale = extra_attributes['locale'] | ||
self.email = extra_attributes["email"] | ||
end | ||
end | ||
end | ||
|
||
def self.load_hooks! | ||
Dir["#{Dir.pwd}/lib/bushido/**/*.rb"].each { |file| load file } | ||
end | ||
|
||
end | ||
end | ||
|
||
if Bushido::Platform.on_bushido? | ||
class BushidoRailtie < Rails::Railtie | ||
config.to_prepare do | ||
puts "Enabling Bushido" | ||
Fulcrum::Bushido.enable_bushido! | ||
puts "Finished enabling Bushido" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class BushidoAppHooks < Bushido::EventObserver | ||
# This is here for eventual lazy-registration. Create a fake user on | ||
# rake bushido:install, and when the app is claimed, we'll get this | ||
# event with the user info, so we convert the existing user and | ||
# update their info here. | ||
def app_claimed | ||
User.order("created_at").first.update_attributes(:email => params['data']['email'], | ||
:ido_id => params['data']['ido_id']) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class BushidoUserHooks < Bushido::EventObserver | ||
def user_added | ||
puts "Adding a new user with incoming data #{params.inspect}" | ||
puts "Devise username column: #{::Devise.cas_username_column}=" | ||
puts "Setting username to: #{params['data'].try(:[], 'ido_id')}" | ||
|
||
user = User.new(:email => params['data'].try(:[], 'email')) | ||
user.name = user.email.split('@').first | ||
user.initials = user.email[0..1].upcase | ||
user.send("#{::Devise.cas_username_column}=".to_sym, params['data'].try(:[], 'ido_id')) | ||
user.save | ||
|
||
# Add the new user to all existing projects | ||
Project.all.each(&:add_all_users!) | ||
end | ||
|
||
def user_removed | ||
puts "Removing user based on incoming data #{params.inspect}" | ||
puts "Devise username column: #{::Devise.cas_username_column}=" | ||
|
||
user = User.find_by_ido_id(params['data']['ido_id']) | ||
|
||
user.try(:remove_all_projects!) | ||
|
||
# TODO: Disable the user instead of destroying them (to prevent data loss) | ||
user.try(:destroy) | ||
end | ||
|
||
def user_updated | ||
puts "Updating user based on incoming data #{params.inspect}" | ||
puts "Devise username column: #{::Devise.cas_username_column}=" | ||
|
||
data = params['data'] | ||
user = User.find_by_ido_id(data['ido_id']) | ||
|
||
if user | ||
# Re-use the CAS login method to set all the extra attributes we | ||
# care about (first_name, last_name, email, local, timezone, | ||
# etc.) | ||
user.bushido_extra_attributes(data) | ||
user.save | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
namespace :bushido do | ||
desc "Run the initial setup for a Busido app. Copies config files and seeds db." | ||
task :install => :environment do | ||
channel = Channel.new :name => "Lobby" | ||
if channel.save | ||
puts "Created the default channel" | ||
else | ||
puts "Error creating the default channel" | ||
user = User.first | ||
|
||
if user.nil? | ||
puts "Creating default user..." | ||
user = User.new | ||
user.email = "#{::Bushido::Platform.name}@#{ENV['BUSHIDO_HOST']}" | ||
user.first_name = ::Bushido::Platform.name[0..1].upcase | ||
user.last_name = ::Bushido::Platform.name | ||
user.ido_id = "temporary_user" | ||
user.save! | ||
end | ||
|
||
channel = Channel.first | ||
|
||
if channel.nil? | ||
puts "Creating default channel..." | ||
channel = Channel.create :name => "Lobby" | ||
end | ||
end | ||
end | ||
end |