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'
class Admin::VersionsController < Admin::AdminController
def show
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
# Don't contact discourse.org
render json: success_json.merge( latest_version: Discourse::VERSION::STRING, installed_version: Discourse::VERSION::STRING )
end
rescue RestClient::Forbidden
render json: {errors: [I18n.t("mothership.access_token_problem")]}
render json: {errors: [I18n.t("discourse_hub.access_token_problem")]}
end
end

View File

@ -1,4 +1,4 @@
require_dependency 'mothership'
require_dependency 'discourse_hub'
class UsersController < ApplicationController
@ -80,7 +80,7 @@ class UsersController < ApplicationController
validator = UsernameValidator.new(params[:username])
if !validator.valid_format?
render json: {errors: validator.errors}
elsif !SiteSetting.call_mothership?
elsif !SiteSetting.call_discourse_hub?
if User.username_available?(params[:username])
render json: {available: true}
else
@ -88,16 +88,16 @@ class UsersController < ApplicationController
end
else
# Contact the mothership
# Contact the Discourse Hub server
email_given = (params[:email].present? or current_user.present?)
available_locally = User.username_available?(params[:username])
global_match = false
available_globally, suggestion_from_mothership = begin
available_globally, suggestion_from_discourse_hub = begin
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]
else
Mothership.nickname_available?(params[:username])
DiscourseHub.nickname_available?(params[:username])
end
end
@ -105,12 +105,12 @@ class UsersController < ApplicationController
render json: {available: true, global_match: (global_match ? true : false)}
elsif available_locally and !available_globally
if email_given
# Nickname and email do not match what's registered on the mothership.
render json: {available: false, global_match: false, suggestion: suggestion_from_mothership}
# Nickname and email do not match what's registered on the discourse hub.
render json: {available: false, global_match: false, suggestion: suggestion_from_discourse_hub}
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.
# 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}
end
elsif available_globally and !available_locally
@ -118,12 +118,12 @@ class UsersController < ApplicationController
render json: {available: false, suggestion: User.suggest_username(params[:username])}
else
# Not available anywhere.
render json: {available: false, suggestion: suggestion_from_mothership}
render json: {available: false, suggestion: suggestion_from_discourse_hub}
end
end
rescue RestClient::Forbidden
render json: {errors: [I18n.t("mothership.access_token_problem")]}
render json: {errors: [I18n.t("discourse_hub.access_token_problem")]}
end
def create
@ -145,7 +145,7 @@ class UsersController < ApplicationController
end
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
@ -188,10 +188,10 @@ class UsersController < ApplicationController
else
render :json => {success: false, message: I18n.t("login.errors", errors: user.errors.full_messages.join("\n"))}
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])) )}
rescue RestClient::Forbidden
render json: {errors: [I18n.t("mothership.access_token_problem")]}
render json: {errors: [I18n.t("discourse_hub.access_token_problem")]}
end
def get_honeypot_value

View File

@ -138,7 +138,7 @@ class SiteSetting < ActiveRecord::Base
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?
end

View File

@ -91,9 +91,9 @@ class User < ActiveRecord::Base
def self.create_for_email(email, opts={})
username = suggest_username(email)
if SiteSetting.call_mothership?
if SiteSetting.call_discourse_hub?
begin
match, available, suggestion = Mothership.nickname_match?( username, email )
match, available, suggestion = DiscourseHub.nickname_match?( username, email )
username = suggestion unless match or available
rescue => e
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.save!
if SiteSetting.call_mothership?
if SiteSetting.call_discourse_hub?
begin
Mothership.register_nickname( username, email )
DiscourseHub.register_nickname( username, email )
rescue => e
Rails.logger.error e.message + "\n" + e.backtrace.join("\n")
end
@ -142,10 +142,10 @@ class User < ActiveRecord::Base
current_username = self.username
self.username = new_username
if SiteSetting.call_mothership? and self.valid?
if SiteSetting.call_discourse_hub? and self.valid?
begin
Mothership.change_nickname( current_username, new_username )
rescue Mothership::NicknameUnavailable
DiscourseHub.change_nickname( current_username, new_username )
rescue DiscourseHub::NicknameUnavailable
return false
rescue => e
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.
mothership:
discourse_hub:
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'
module Mothership
module DiscourseHub
class NicknameUnavailable < RuntimeError; end
@ -41,25 +41,25 @@ module Mothership
private
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)
end
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)
end
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)
end
def self.mothership_base_url
def self.hub_base_url
if Rails.env == 'production'
'http://api.discourse.org/api'
else
'http://local.mothership:3000/api'
'http://local.hub:3000/api'
end
end

View File

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

View File

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

View File

@ -77,33 +77,33 @@ describe SiteSetting do
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
SiteSetting.enforce_global_nicknames = true
SiteSetting.discourse_org_access_key = 'asdfasfsafd'
SiteSetting.refresh!
SiteSetting.call_mothership?.should == true
SiteSetting.call_discourse_hub?.should == true
end
it 'should be false when enforce_global_nicknames is false and discourse_org_access_key is set' do
SiteSetting.enforce_global_nicknames = false
SiteSetting.discourse_org_access_key = 'asdfasfsafd'
SiteSetting.refresh!
SiteSetting.call_mothership?.should == false
SiteSetting.call_discourse_hub?.should == false
end
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.discourse_org_access_key = ''
SiteSetting.refresh!
SiteSetting.call_mothership?.should == false
SiteSetting.call_discourse_hub?.should == false
end
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.discourse_org_access_key = ''
SiteSetting.refresh!
SiteSetting.call_mothership?.should == false
SiteSetting.call_discourse_hub?.should == false
end
end