Replace mentions of mothership with discourse_hub

This commit is contained in:
Neil Lalonde 2013-02-14 12:57:26 -05:00
parent 68f32af240
commit 39eab7c425
9 changed files with 74 additions and 75 deletions

View File

@ -1,15 +1,15 @@
require_dependency 'mothership' require_dependency 'discourse_hub'
require_dependency 'version' require_dependency 'version'
class Admin::VersionsController < Admin::AdminController class Admin::VersionsController < Admin::AdminController
def show def show
if SiteSetting.discourse_org_access_key.present? if SiteSetting.discourse_org_access_key.present?
render json: success_json.merge( latest_version: Mothership.current_discourse_version, installed_version: Discourse::VERSION::STRING ) render json: success_json.merge( latest_version: DiscourseHub.current_discourse_version, installed_version: Discourse::VERSION::STRING )
else else
# Don't contact discourse.org # Don't contact discourse.org
render json: success_json.merge( latest_version: Discourse::VERSION::STRING, installed_version: Discourse::VERSION::STRING ) render json: success_json.merge( latest_version: Discourse::VERSION::STRING, installed_version: Discourse::VERSION::STRING )
end end
rescue RestClient::Forbidden rescue RestClient::Forbidden
render json: {errors: [I18n.t("mothership.access_token_problem")]} render json: {errors: [I18n.t("discourse_hub.access_token_problem")]}
end end
end end

View File

@ -1,4 +1,4 @@
require_dependency 'mothership' require_dependency 'discourse_hub'
class UsersController < ApplicationController class UsersController < ApplicationController
@ -80,7 +80,7 @@ class UsersController < ApplicationController
validator = UsernameValidator.new(params[:username]) validator = UsernameValidator.new(params[:username])
if !validator.valid_format? if !validator.valid_format?
render json: {errors: validator.errors} render json: {errors: validator.errors}
elsif !SiteSetting.call_mothership? elsif !SiteSetting.call_discourse_hub?
if User.username_available?(params[:username]) if User.username_available?(params[:username])
render json: {available: true} render json: {available: true}
else else
@ -88,16 +88,16 @@ class UsersController < ApplicationController
end end
else else
# Contact the mothership # Contact the Discourse Hub server
email_given = (params[:email].present? or current_user.present?) email_given = (params[:email].present? or current_user.present?)
available_locally = User.username_available?(params[:username]) available_locally = User.username_available?(params[:username])
global_match = false global_match = false
available_globally, suggestion_from_mothership = begin available_globally, suggestion_from_discourse_hub = begin
if email_given if email_given
global_match, available, suggestion = Mothership.nickname_match?( params[:username], params[:email] || current_user.email ) global_match, available, suggestion = DiscourseHub.nickname_match?( params[:username], params[:email] || current_user.email )
[available || global_match, suggestion] [available || global_match, suggestion]
else else
Mothership.nickname_available?(params[:username]) DiscourseHub.nickname_available?(params[:username])
end end
end end
@ -105,12 +105,12 @@ class UsersController < ApplicationController
render json: {available: true, global_match: (global_match ? true : false)} render json: {available: true, global_match: (global_match ? true : false)}
elsif available_locally and !available_globally elsif available_locally and !available_globally
if email_given if email_given
# Nickname and email do not match what's registered on the mothership. # Nickname and email do not match what's registered on the discourse hub.
render json: {available: false, global_match: false, suggestion: suggestion_from_mothership} render json: {available: false, global_match: false, suggestion: suggestion_from_discourse_hub}
else else
# The nickname is available locally, but is registered on the mothership. # The nickname is available locally, but is registered on the discourse hub.
# We need an email to see if the nickname belongs to this person. # We need an email to see if the nickname belongs to this person.
# Don't give a suggestion until we get the email and try to match it with on the mothership. # Don't give a suggestion until we get the email and try to match it with on the discourse hub.
render json: {available: false} render json: {available: false}
end end
elsif available_globally and !available_locally elsif available_globally and !available_locally
@ -118,12 +118,12 @@ class UsersController < ApplicationController
render json: {available: false, suggestion: User.suggest_username(params[:username])} render json: {available: false, suggestion: User.suggest_username(params[:username])}
else else
# Not available anywhere. # Not available anywhere.
render json: {available: false, suggestion: suggestion_from_mothership} render json: {available: false, suggestion: suggestion_from_discourse_hub}
end end
end end
rescue RestClient::Forbidden rescue RestClient::Forbidden
render json: {errors: [I18n.t("mothership.access_token_problem")]} render json: {errors: [I18n.t("discourse_hub.access_token_problem")]}
end end
def create def create
@ -145,7 +145,7 @@ class UsersController < ApplicationController
end end
user.password_required unless auth user.password_required unless auth
Mothership.register_nickname( user.username, user.email ) if user.valid? and SiteSetting.call_mothership? DiscourseHub.register_nickname( user.username, user.email ) if user.valid? and SiteSetting.call_discourse_hub?
if user.save if user.save
@ -188,10 +188,10 @@ class UsersController < ApplicationController
else else
render :json => {success: false, message: I18n.t("login.errors", errors: user.errors.full_messages.join("\n"))} render :json => {success: false, message: I18n.t("login.errors", errors: user.errors.full_messages.join("\n"))}
end end
rescue Mothership::NicknameUnavailable rescue DiscourseHub::NicknameUnavailable
render :json => {success: false, message: I18n.t("login.errors", errors:I18n.t("login.not_available", suggestion: User.suggest_username(params[:username])) )} render :json => {success: false, message: I18n.t("login.errors", errors:I18n.t("login.not_available", suggestion: User.suggest_username(params[:username])) )}
rescue RestClient::Forbidden rescue RestClient::Forbidden
render json: {errors: [I18n.t("mothership.access_token_problem")]} render json: {errors: [I18n.t("discourse_hub.access_token_problem")]}
end end
def get_honeypot_value def get_honeypot_value

View File

@ -138,7 +138,7 @@ class SiteSetting < ActiveRecord::Base
setting(:new_user_period_days, 2) setting(:new_user_period_days, 2)
def self.call_mothership? def self.call_discourse_hub?
self.enforce_global_nicknames? and self.discourse_org_access_key.present? self.enforce_global_nicknames? and self.discourse_org_access_key.present?
end end

View File

@ -91,9 +91,9 @@ class User < ActiveRecord::Base
def self.create_for_email(email, opts={}) def self.create_for_email(email, opts={})
username = suggest_username(email) username = suggest_username(email)
if SiteSetting.call_mothership? if SiteSetting.call_discourse_hub?
begin begin
match, available, suggestion = Mothership.nickname_match?( username, email ) match, available, suggestion = DiscourseHub.nickname_match?( username, email )
username = suggestion unless match or available username = suggestion unless match or available
rescue => e rescue => e
Rails.logger.error e.message + "\n" + e.backtrace.join("\n") Rails.logger.error e.message + "\n" + e.backtrace.join("\n")
@ -104,9 +104,9 @@ class User < ActiveRecord::Base
user.trust_level = opts[:trust_level] if opts[:trust_level].present? user.trust_level = opts[:trust_level] if opts[:trust_level].present?
user.save! user.save!
if SiteSetting.call_mothership? if SiteSetting.call_discourse_hub?
begin begin
Mothership.register_nickname( username, email ) DiscourseHub.register_nickname( username, email )
rescue => e rescue => e
Rails.logger.error e.message + "\n" + e.backtrace.join("\n") Rails.logger.error e.message + "\n" + e.backtrace.join("\n")
end end
@ -142,10 +142,10 @@ class User < ActiveRecord::Base
current_username = self.username current_username = self.username
self.username = new_username self.username = new_username
if SiteSetting.call_mothership? and self.valid? if SiteSetting.call_discourse_hub? and self.valid?
begin begin
Mothership.change_nickname( current_username, new_username ) DiscourseHub.change_nickname( current_username, new_username )
rescue Mothership::NicknameUnavailable rescue DiscourseHub::NicknameUnavailable
return false return false
rescue => e rescue => e
Rails.logger.error e.message + "\n" + e.backtrace.join("\n") Rails.logger.error e.message + "\n" + e.backtrace.join("\n")

View File

@ -1337,5 +1337,5 @@ en:
If the above link is not clickable, try copying and pasting it into the address bar of your web browser. If the above link is not clickable, try copying and pasting it into the address bar of your web browser.
mothership: discourse_hub:
access_token_problem: "Tell an admin: Please update the site settings to include the correct discourse_org_access_key." access_token_problem: "Tell an admin: Please update the site settings to include the correct discourse_org_access_key."

View File

@ -1,6 +1,6 @@
require_dependency 'rest_client' require_dependency 'rest_client'
module Mothership module DiscourseHub
class NicknameUnavailable < RuntimeError; end class NicknameUnavailable < RuntimeError; end
@ -41,25 +41,25 @@ module Mothership
private private
def self.get(rel_url, params={}) def self.get(rel_url, params={})
response = RestClient.get( "#{mothership_base_url}#{rel_url}", {params: {access_token: access_token}.merge(params), accept: accepts } ) response = RestClient.get( "#{hub_base_url}#{rel_url}", {params: {access_token: access_token}.merge(params), accept: accepts } )
JSON.parse(response) JSON.parse(response)
end end
def self.post(rel_url, params={}) def self.post(rel_url, params={})
response = RestClient.post( "#{mothership_base_url}#{rel_url}", {access_token: access_token}.merge(params), content_type: :json, accept: accepts ) response = RestClient.post( "#{hub_base_url}#{rel_url}", {access_token: access_token}.merge(params), content_type: :json, accept: accepts )
JSON.parse(response) JSON.parse(response)
end end
def self.put(rel_url, params={}) def self.put(rel_url, params={})
response = RestClient.put( "#{mothership_base_url}#{rel_url}", {access_token: access_token}.merge(params), content_type: :json, accept: accepts ) response = RestClient.put( "#{hub_base_url}#{rel_url}", {access_token: access_token}.merge(params), content_type: :json, accept: accepts )
JSON.parse(response) JSON.parse(response)
end end
def self.mothership_base_url def self.hub_base_url
if Rails.env == 'production' if Rails.env == 'production'
'http://api.discourse.org/api' 'http://api.discourse.org/api'
else else
'http://local.mothership:3000/api' 'http://local.hub:3000/api'
end end
end end

View File

@ -1,16 +1,16 @@
require 'spec_helper' require 'spec_helper'
require_dependency 'mothership' require_dependency 'discourse_hub'
describe Mothership do describe DiscourseHub do
describe '#nickname_available?' do describe '#nickname_available?' do
it 'should return true when nickname is available and no suggestion' do it 'should return true when nickname is available and no suggestion' do
RestClient.stubs(:get).returns( {success: 'OK', available: true}.to_json ) RestClient.stubs(:get).returns( {success: 'OK', available: true}.to_json )
Mothership.nickname_available?('MacGyver').should == [true, nil] DiscourseHub.nickname_available?('MacGyver').should == [true, nil]
end end
it 'should return false and a suggestion when nickname is not available' do it 'should return false and a suggestion when nickname is not available' do
RestClient.stubs(:get).returns( {success: 'OK', available: false, suggestion: 'MacGyver1'}.to_json ) RestClient.stubs(:get).returns( {success: 'OK', available: false, suggestion: 'MacGyver1'}.to_json )
available, suggestion = Mothership.nickname_available?('MacGyver') available, suggestion = DiscourseHub.nickname_available?('MacGyver')
available.should be_false available.should be_false
suggestion.should_not be_nil suggestion.should_not be_nil
end end
@ -21,12 +21,12 @@ describe Mothership do
describe '#nickname_match?' do describe '#nickname_match?' do
it 'should return true when it is a match and no suggestion' do it 'should return true when it is a match and no suggestion' do
RestClient.stubs(:get).returns( {success: 'OK', match: true, available: false}.to_json ) RestClient.stubs(:get).returns( {success: 'OK', match: true, available: false}.to_json )
Mothership.nickname_match?('MacGyver', 'macg@example.com').should == [true, false, nil] DiscourseHub.nickname_match?('MacGyver', 'macg@example.com').should == [true, false, nil]
end end
it 'should return false and a suggestion when it is not a match and the nickname is not available' do it 'should return false and a suggestion when it is not a match and the nickname is not available' do
RestClient.stubs(:get).returns( {success: 'OK', match: false, available: false, suggestion: 'MacGyver1'}.to_json ) RestClient.stubs(:get).returns( {success: 'OK', match: false, available: false, suggestion: 'MacGyver1'}.to_json )
match, available, suggestion = Mothership.nickname_match?('MacGyver', 'macg@example.com') match, available, suggestion = DiscourseHub.nickname_match?('MacGyver', 'macg@example.com')
match.should be_false match.should be_false
available.should be_false available.should be_false
suggestion.should_not be_nil suggestion.should_not be_nil
@ -34,7 +34,7 @@ describe Mothership do
it 'should return false and no suggestion when it is not a match and the nickname is available' do it 'should return false and no suggestion when it is not a match and the nickname is available' do
RestClient.stubs(:get).returns( {success: 'OK', match: false, available: true}.to_json ) RestClient.stubs(:get).returns( {success: 'OK', match: false, available: true}.to_json )
match, available, suggestion = Mothership.nickname_match?('MacGyver', 'macg@example.com') match, available, suggestion = DiscourseHub.nickname_match?('MacGyver', 'macg@example.com')
match.should be_false match.should be_false
available.should be_true available.should be_true
suggestion.should be_nil suggestion.should be_nil
@ -44,51 +44,50 @@ describe Mothership do
describe '#register_nickname' do describe '#register_nickname' do
it 'should return true when registration succeeds' do it 'should return true when registration succeeds' do
RestClient.stubs(:post).returns( {success: 'OK'}.to_json ) RestClient.stubs(:post).returns( {success: 'OK'}.to_json )
Mothership.register_nickname('MacGyver', 'macg@example.com').should be_true DiscourseHub.register_nickname('MacGyver', 'macg@example.com').should be_true
end end
it 'should return raise an exception when registration fails' do it 'should return raise an exception when registration fails' do
RestClient.stubs(:post).returns( {failed: -200}.to_json ) RestClient.stubs(:post).returns( {failed: -200}.to_json )
expect { expect {
Mothership.register_nickname('MacGyver', 'macg@example.com') DiscourseHub.register_nickname('MacGyver', 'macg@example.com')
}.to raise_error(Mothership::NicknameUnavailable) }.to raise_error(DiscourseHub::NicknameUnavailable)
end end
end end
describe '#current_discourse_version' do describe '#current_discourse_version' do
it 'should return the latest version of discourse' do it 'should return the latest version of discourse' do
RestClient.stubs(:get).returns( {success: 'OK', version: 1.0}.to_json ) RestClient.stubs(:get).returns( {success: 'OK', version: 1.0}.to_json )
Mothership.current_discourse_version().should == 1.0 DiscourseHub.current_discourse_version().should == 1.0
end end
end end
describe '#change_nickname' do describe '#change_nickname' do
it 'should return true when nickname is changed successfully' do it 'should return true when nickname is changed successfully' do
RestClient.stubs(:put).returns( {success: 'OK'}.to_json ) RestClient.stubs(:put).returns( {success: 'OK'}.to_json )
Mothership.change_nickname('MacGyver', 'MacG').should be_true DiscourseHub.change_nickname('MacGyver', 'MacG').should be_true
end end
it 'should return raise NicknameUnavailable when nickname is not available' do it 'should return raise NicknameUnavailable when nickname is not available' do
RestClient.stubs(:put).returns( {failed: -200}.to_json ) RestClient.stubs(:put).returns( {failed: -200}.to_json )
expect { expect {
Mothership.change_nickname('MacGyver', 'MacG') DiscourseHub.change_nickname('MacGyver', 'MacG')
}.to raise_error(Mothership::NicknameUnavailable) }.to raise_error(DiscourseHub::NicknameUnavailable)
end end
# TODO: General error handling in mothership.rb
# it 'should return raise NicknameUnavailable when nickname does not belong to this forum' do # it 'should return raise NicknameUnavailable when nickname does not belong to this forum' do
# RestClient.stubs(:put).returns( {failed: -13}.to_json ) # RestClient.stubs(:put).returns( {failed: -13}.to_json )
# expect { # expect {
# Mothership.change_nickname('MacGyver', 'MacG') # DiscourseHub.change_nickname('MacGyver', 'MacG')
# }.to raise_error(Mothership::ActionForbidden) # }.to raise_error(DiscourseHub::ActionForbidden)
# end # end
# it 'should return raise NicknameUnavailable when nickname does not belong to this forum' do # it 'should return raise NicknameUnavailable when nickname does not belong to this forum' do
# RestClient.stubs(:put).returns( {failed: -13}.to_json ) # RestClient.stubs(:put).returns( {failed: -13}.to_json )
# expect { # expect {
# Mothership.change_nickname('MacGyver', 'MacG') # DiscourseHub.change_nickname('MacGyver', 'MacG')
# }.to raise_error(Mothership::ActionForbidden) # }.to raise_error(DiscourseHub::ActionForbidden)
# end # end
end end
end end

View File

@ -270,7 +270,7 @@ describe UsersController do
before do before do
@user = Fabricate.build(:user) @user = Fabricate.build(:user)
@user.password = "strongpassword" @user.password = "strongpassword"
Mothership.stubs(:register_nickname).returns([true, nil]) DiscourseHub.stubs(:register_nickname).returns([true, nil])
end end
context 'when creating a non active user (unconfirmed email)' do context 'when creating a non active user (unconfirmed email)' do
@ -438,7 +438,7 @@ describe UsersController do
context '.check_username' do context '.check_username' do
before do before do
Mothership.stubs(:nickname_available?).returns([true, nil]) DiscourseHub.stubs(:nickname_available?).returns([true, nil])
end end
it 'raises an error without a username parameter' do it 'raises an error without a username parameter' do
@ -469,11 +469,11 @@ describe UsersController do
end end
end end
context 'when call_mothership is disabled' do context 'when call_discourse_hub is disabled' do
before do before do
SiteSetting.stubs(:call_mothership?).returns(false) SiteSetting.stubs(:call_discourse_hub?).returns(false)
Mothership.expects(:nickname_available?).never DiscourseHub.expects(:nickname_available?).never
Mothership.expects(:nickname_match?).never DiscourseHub.expects(:nickname_match?).never
end end
context 'available everywhere' do context 'available everywhere' do
@ -543,15 +543,15 @@ describe UsersController do
end end
end end
context 'when call_mothership is enabled' do context 'when call_discourse_hub is enabled' do
before do before do
SiteSetting.stubs(:call_mothership?).returns(true) SiteSetting.stubs(:call_discourse_hub?).returns(true)
end end
context 'available locally and globally' do context 'available locally and globally' do
before do before do
Mothership.stubs(:nickname_available?).returns([true, nil]) DiscourseHub.stubs(:nickname_available?).returns([true, nil])
Mothership.stubs(:nickname_match?).returns([false, true, nil]) # match = false, available = true, suggestion = nil DiscourseHub.stubs(:nickname_match?).returns([false, true, nil]) # match = false, available = true, suggestion = nil
end end
shared_examples_for 'check_username when nickname is available everywhere' do shared_examples_for 'check_username when nickname is available everywhere' do
@ -599,7 +599,7 @@ describe UsersController do
context 'available locally but not globally' do context 'available locally but not globally' do
before do before do
Mothership.stubs(:nickname_available?).returns([false, 'suggestion']) DiscourseHub.stubs(:nickname_available?).returns([false, 'suggestion'])
end end
context 'email param is not given' do context 'email param is not given' do
@ -618,7 +618,7 @@ describe UsersController do
context 'email matches global nickname' do context 'email matches global nickname' do
before do before do
Mothership.stubs(:nickname_match?).returns([true, false, nil]) DiscourseHub.stubs(:nickname_match?).returns([true, false, nil])
xhr :get, :check_username, username: 'BruceWayne', email: 'brucie@example.com' xhr :get, :check_username, username: 'BruceWayne', email: 'brucie@example.com'
end end
it_should_behave_like 'when username is available everywhere' it_should_behave_like 'when username is available everywhere'
@ -630,7 +630,7 @@ describe UsersController do
context 'email does not match global nickname' do context 'email does not match global nickname' do
before do before do
Mothership.stubs(:nickname_match?).returns([false, false, 'suggestion']) DiscourseHub.stubs(:nickname_match?).returns([false, false, 'suggestion'])
xhr :get, :check_username, username: 'BruceWayne', email: 'brucie@example.com' xhr :get, :check_username, username: 'BruceWayne', email: 'brucie@example.com'
end end
it_should_behave_like 'when username is unavailable locally' it_should_behave_like 'when username is unavailable locally'
@ -645,7 +645,7 @@ describe UsersController do
let!(:user) { Fabricate(:user) } let!(:user) { Fabricate(:user) }
before do before do
Mothership.stubs(:nickname_available?).returns([false, 'suggestion']) DiscourseHub.stubs(:nickname_available?).returns([false, 'suggestion'])
xhr :get, :check_username, username: user.username xhr :get, :check_username, username: user.username
end end
@ -656,7 +656,7 @@ describe UsersController do
let!(:user) { Fabricate(:user) } let!(:user) { Fabricate(:user) }
before do before do
Mothership.stubs(:nickname_available?).returns([true, nil]) DiscourseHub.stubs(:nickname_available?).returns([true, nil])
xhr :get, :check_username, username: user.username xhr :get, :check_username, username: user.username
end end
@ -666,9 +666,9 @@ describe UsersController do
context 'when discourse_org_access_key is wrong' do context 'when discourse_org_access_key is wrong' do
before do before do
SiteSetting.stubs(:call_mothership?).returns(true) SiteSetting.stubs(:call_discourse_hub?).returns(true)
Mothership.stubs(:nickname_available?).raises(RestClient::Forbidden) DiscourseHub.stubs(:nickname_available?).raises(RestClient::Forbidden)
Mothership.stubs(:nickname_match?).raises(RestClient::Forbidden) DiscourseHub.stubs(:nickname_match?).raises(RestClient::Forbidden)
end end
it 'should return an error message' do it 'should return an error message' do

View File

@ -77,33 +77,33 @@ describe SiteSetting do
end end
end end
describe 'call_mothership?' do describe 'call_discourse_hub?' do
it 'should be true when enforce_global_nicknames is true and discourse_org_access_key is set' do it 'should be true when enforce_global_nicknames is true and discourse_org_access_key is set' do
SiteSetting.enforce_global_nicknames = true SiteSetting.enforce_global_nicknames = true
SiteSetting.discourse_org_access_key = 'asdfasfsafd' SiteSetting.discourse_org_access_key = 'asdfasfsafd'
SiteSetting.refresh! SiteSetting.refresh!
SiteSetting.call_mothership?.should == true SiteSetting.call_discourse_hub?.should == true
end end
it 'should be false when enforce_global_nicknames is false and discourse_org_access_key is set' do it 'should be false when enforce_global_nicknames is false and discourse_org_access_key is set' do
SiteSetting.enforce_global_nicknames = false SiteSetting.enforce_global_nicknames = false
SiteSetting.discourse_org_access_key = 'asdfasfsafd' SiteSetting.discourse_org_access_key = 'asdfasfsafd'
SiteSetting.refresh! SiteSetting.refresh!
SiteSetting.call_mothership?.should == false SiteSetting.call_discourse_hub?.should == false
end end
it 'should be false when enforce_global_nicknames is true and discourse_org_access_key is not set' do it 'should be false when enforce_global_nicknames is true and discourse_org_access_key is not set' do
SiteSetting.enforce_global_nicknames = true SiteSetting.enforce_global_nicknames = true
SiteSetting.discourse_org_access_key = '' SiteSetting.discourse_org_access_key = ''
SiteSetting.refresh! SiteSetting.refresh!
SiteSetting.call_mothership?.should == false SiteSetting.call_discourse_hub?.should == false
end end
it 'should be false when enforce_global_nicknames is false and discourse_org_access_key is not set' do it 'should be false when enforce_global_nicknames is false and discourse_org_access_key is not set' do
SiteSetting.enforce_global_nicknames = false SiteSetting.enforce_global_nicknames = false
SiteSetting.discourse_org_access_key = '' SiteSetting.discourse_org_access_key = ''
SiteSetting.refresh! SiteSetting.refresh!
SiteSetting.call_mothership?.should == false SiteSetting.call_discourse_hub?.should == false
end end
end end