Skip to content

Commit 39eab7c

Browse files
committed
Replace mentions of mothership with discourse_hub
1 parent 68f32af commit 39eab7c

9 files changed

Lines changed: 74 additions & 75 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
require_dependency 'mothership'
1+
require_dependency 'discourse_hub'
22
require_dependency 'version'
33

44
class Admin::VersionsController < Admin::AdminController
55
def show
66
if SiteSetting.discourse_org_access_key.present?
7-
render json: success_json.merge( latest_version: Mothership.current_discourse_version, installed_version: Discourse::VERSION::STRING )
7+
render json: success_json.merge( latest_version: DiscourseHub.current_discourse_version, installed_version: Discourse::VERSION::STRING )
88
else
99
# Don't contact discourse.org
1010
render json: success_json.merge( latest_version: Discourse::VERSION::STRING, installed_version: Discourse::VERSION::STRING )
1111
end
1212
rescue RestClient::Forbidden
13-
render json: {errors: [I18n.t("mothership.access_token_problem")]}
13+
render json: {errors: [I18n.t("discourse_hub.access_token_problem")]}
1414
end
1515
end

app/controllers/users_controller.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_dependency 'mothership'
1+
require_dependency 'discourse_hub'
22

33
class UsersController < ApplicationController
44

@@ -80,50 +80,50 @@ def check_username
8080
validator = UsernameValidator.new(params[:username])
8181
if !validator.valid_format?
8282
render json: {errors: validator.errors}
83-
elsif !SiteSetting.call_mothership?
83+
elsif !SiteSetting.call_discourse_hub?
8484
if User.username_available?(params[:username])
8585
render json: {available: true}
8686
else
8787
render json: {available: false, suggestion: User.suggest_username(params[:username])}
8888
end
8989
else
9090

91-
# Contact the mothership
91+
# Contact the Discourse Hub server
9292
email_given = (params[:email].present? or current_user.present?)
9393
available_locally = User.username_available?(params[:username])
9494
global_match = false
95-
available_globally, suggestion_from_mothership = begin
95+
available_globally, suggestion_from_discourse_hub = begin
9696
if email_given
97-
global_match, available, suggestion = Mothership.nickname_match?( params[:username], params[:email] || current_user.email )
97+
global_match, available, suggestion = DiscourseHub.nickname_match?( params[:username], params[:email] || current_user.email )
9898
[available || global_match, suggestion]
9999
else
100-
Mothership.nickname_available?(params[:username])
100+
DiscourseHub.nickname_available?(params[:username])
101101
end
102102
end
103103

104104
if available_globally and available_locally
105105
render json: {available: true, global_match: (global_match ? true : false)}
106106
elsif available_locally and !available_globally
107107
if email_given
108-
# Nickname and email do not match what's registered on the mothership.
109-
render json: {available: false, global_match: false, suggestion: suggestion_from_mothership}
108+
# Nickname and email do not match what's registered on the discourse hub.
109+
render json: {available: false, global_match: false, suggestion: suggestion_from_discourse_hub}
110110
else
111-
# The nickname is available locally, but is registered on the mothership.
111+
# The nickname is available locally, but is registered on the discourse hub.
112112
# We need an email to see if the nickname belongs to this person.
113-
# Don't give a suggestion until we get the email and try to match it with on the mothership.
113+
# Don't give a suggestion until we get the email and try to match it with on the discourse hub.
114114
render json: {available: false}
115115
end
116116
elsif available_globally and !available_locally
117117
# Already registered on this site with the matching nickname and email address. Why are you signing up again?
118118
render json: {available: false, suggestion: User.suggest_username(params[:username])}
119119
else
120120
# Not available anywhere.
121-
render json: {available: false, suggestion: suggestion_from_mothership}
121+
render json: {available: false, suggestion: suggestion_from_discourse_hub}
122122
end
123123

124124
end
125125
rescue RestClient::Forbidden
126-
render json: {errors: [I18n.t("mothership.access_token_problem")]}
126+
render json: {errors: [I18n.t("discourse_hub.access_token_problem")]}
127127
end
128128

129129
def create
@@ -145,7 +145,7 @@ def create
145145
end
146146
user.password_required unless auth
147147

148-
Mothership.register_nickname( user.username, user.email ) if user.valid? and SiteSetting.call_mothership?
148+
DiscourseHub.register_nickname( user.username, user.email ) if user.valid? and SiteSetting.call_discourse_hub?
149149

150150
if user.save
151151

@@ -188,10 +188,10 @@ def create
188188
else
189189
render :json => {success: false, message: I18n.t("login.errors", errors: user.errors.full_messages.join("\n"))}
190190
end
191-
rescue Mothership::NicknameUnavailable
191+
rescue DiscourseHub::NicknameUnavailable
192192
render :json => {success: false, message: I18n.t("login.errors", errors:I18n.t("login.not_available", suggestion: User.suggest_username(params[:username])) )}
193193
rescue RestClient::Forbidden
194-
render json: {errors: [I18n.t("mothership.access_token_problem")]}
194+
render json: {errors: [I18n.t("discourse_hub.access_token_problem")]}
195195
end
196196

197197
def get_honeypot_value

app/models/site_setting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class SiteSetting < ActiveRecord::Base
138138

139139
setting(:new_user_period_days, 2)
140140

141-
def self.call_mothership?
141+
def self.call_discourse_hub?
142142
self.enforce_global_nicknames? and self.discourse_org_access_key.present?
143143
end
144144

app/models/user.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ def self.suggest_username(name)
9191
def self.create_for_email(email, opts={})
9292
username = suggest_username(email)
9393

94-
if SiteSetting.call_mothership?
94+
if SiteSetting.call_discourse_hub?
9595
begin
96-
match, available, suggestion = Mothership.nickname_match?( username, email )
96+
match, available, suggestion = DiscourseHub.nickname_match?( username, email )
9797
username = suggestion unless match or available
9898
rescue => e
9999
Rails.logger.error e.message + "\n" + e.backtrace.join("\n")
@@ -104,9 +104,9 @@ def self.create_for_email(email, opts={})
104104
user.trust_level = opts[:trust_level] if opts[:trust_level].present?
105105
user.save!
106106

107-
if SiteSetting.call_mothership?
107+
if SiteSetting.call_discourse_hub?
108108
begin
109-
Mothership.register_nickname( username, email )
109+
DiscourseHub.register_nickname( username, email )
110110
rescue => e
111111
Rails.logger.error e.message + "\n" + e.backtrace.join("\n")
112112
end
@@ -142,10 +142,10 @@ def change_username(new_username)
142142
current_username = self.username
143143
self.username = new_username
144144

145-
if SiteSetting.call_mothership? and self.valid?
145+
if SiteSetting.call_discourse_hub? and self.valid?
146146
begin
147-
Mothership.change_nickname( current_username, new_username )
148-
rescue Mothership::NicknameUnavailable
147+
DiscourseHub.change_nickname( current_username, new_username )
148+
rescue DiscourseHub::NicknameUnavailable
149149
return false
150150
rescue => e
151151
Rails.logger.error e.message + "\n" + e.backtrace.join("\n")

config/locales/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,5 +1337,5 @@ en:
13371337
13381338
If the above link is not clickable, try copying and pasting it into the address bar of your web browser.
13391339
1340-
mothership:
1340+
discourse_hub:
13411341
access_token_problem: "Tell an admin: Please update the site settings to include the correct discourse_org_access_key."
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require_dependency 'rest_client'
22

3-
module Mothership
3+
module DiscourseHub
44

55
class NicknameUnavailable < RuntimeError; end
66

@@ -41,25 +41,25 @@ def self.current_discourse_version
4141
private
4242

4343
def self.get(rel_url, params={})
44-
response = RestClient.get( "#{mothership_base_url}#{rel_url}", {params: {access_token: access_token}.merge(params), accept: accepts } )
44+
response = RestClient.get( "#{hub_base_url}#{rel_url}", {params: {access_token: access_token}.merge(params), accept: accepts } )
4545
JSON.parse(response)
4646
end
4747

4848
def self.post(rel_url, params={})
49-
response = RestClient.post( "#{mothership_base_url}#{rel_url}", {access_token: access_token}.merge(params), content_type: :json, accept: accepts )
49+
response = RestClient.post( "#{hub_base_url}#{rel_url}", {access_token: access_token}.merge(params), content_type: :json, accept: accepts )
5050
JSON.parse(response)
5151
end
5252

5353
def self.put(rel_url, params={})
54-
response = RestClient.put( "#{mothership_base_url}#{rel_url}", {access_token: access_token}.merge(params), content_type: :json, accept: accepts )
54+
response = RestClient.put( "#{hub_base_url}#{rel_url}", {access_token: access_token}.merge(params), content_type: :json, accept: accepts )
5555
JSON.parse(response)
5656
end
5757

58-
def self.mothership_base_url
58+
def self.hub_base_url
5959
if Rails.env == 'production'
6060
'http://api.discourse.org/api'
6161
else
62-
'http://local.mothership:3000/api'
62+
'http://local.hub:3000/api'
6363
end
6464
end
6565

Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
require 'spec_helper'
2-
require_dependency 'mothership'
2+
require_dependency 'discourse_hub'
33

4-
describe Mothership do
4+
describe DiscourseHub do
55
describe '#nickname_available?' do
66
it 'should return true when nickname is available and no suggestion' do
77
RestClient.stubs(:get).returns( {success: 'OK', available: true}.to_json )
8-
Mothership.nickname_available?('MacGyver').should == [true, nil]
8+
DiscourseHub.nickname_available?('MacGyver').should == [true, nil]
99
end
1010

1111
it 'should return false and a suggestion when nickname is not available' do
1212
RestClient.stubs(:get).returns( {success: 'OK', available: false, suggestion: 'MacGyver1'}.to_json )
13-
available, suggestion = Mothership.nickname_available?('MacGyver')
13+
available, suggestion = DiscourseHub.nickname_available?('MacGyver')
1414
available.should be_false
1515
suggestion.should_not be_nil
1616
end
@@ -21,20 +21,20 @@
2121
describe '#nickname_match?' do
2222
it 'should return true when it is a match and no suggestion' do
2323
RestClient.stubs(:get).returns( {success: 'OK', match: true, available: false}.to_json )
24-
Mothership.nickname_match?('MacGyver', 'macg@example.com').should == [true, false, nil]
24+
DiscourseHub.nickname_match?('MacGyver', 'macg@example.com').should == [true, false, nil]
2525
end
2626

2727
it 'should return false and a suggestion when it is not a match and the nickname is not available' do
2828
RestClient.stubs(:get).returns( {success: 'OK', match: false, available: false, suggestion: 'MacGyver1'}.to_json )
29-
match, available, suggestion = Mothership.nickname_match?('MacGyver', 'macg@example.com')
29+
match, available, suggestion = DiscourseHub.nickname_match?('MacGyver', 'macg@example.com')
3030
match.should be_false
3131
available.should be_false
3232
suggestion.should_not be_nil
3333
end
3434

3535
it 'should return false and no suggestion when it is not a match and the nickname is available' do
3636
RestClient.stubs(:get).returns( {success: 'OK', match: false, available: true}.to_json )
37-
match, available, suggestion = Mothership.nickname_match?('MacGyver', 'macg@example.com')
37+
match, available, suggestion = DiscourseHub.nickname_match?('MacGyver', 'macg@example.com')
3838
match.should be_false
3939
available.should be_true
4040
suggestion.should be_nil
@@ -44,51 +44,50 @@
4444
describe '#register_nickname' do
4545
it 'should return true when registration succeeds' do
4646
RestClient.stubs(:post).returns( {success: 'OK'}.to_json )
47-
Mothership.register_nickname('MacGyver', 'macg@example.com').should be_true
47+
DiscourseHub.register_nickname('MacGyver', 'macg@example.com').should be_true
4848
end
4949

5050
it 'should return raise an exception when registration fails' do
5151
RestClient.stubs(:post).returns( {failed: -200}.to_json )
5252
expect {
53-
Mothership.register_nickname('MacGyver', 'macg@example.com')
54-
}.to raise_error(Mothership::NicknameUnavailable)
53+
DiscourseHub.register_nickname('MacGyver', 'macg@example.com')
54+
}.to raise_error(DiscourseHub::NicknameUnavailable)
5555
end
5656
end
5757

5858
describe '#current_discourse_version' do
5959
it 'should return the latest version of discourse' do
6060
RestClient.stubs(:get).returns( {success: 'OK', version: 1.0}.to_json )
61-
Mothership.current_discourse_version().should == 1.0
61+
DiscourseHub.current_discourse_version().should == 1.0
6262
end
6363
end
6464

6565
describe '#change_nickname' do
6666
it 'should return true when nickname is changed successfully' do
6767
RestClient.stubs(:put).returns( {success: 'OK'}.to_json )
68-
Mothership.change_nickname('MacGyver', 'MacG').should be_true
68+
DiscourseHub.change_nickname('MacGyver', 'MacG').should be_true
6969
end
7070

7171
it 'should return raise NicknameUnavailable when nickname is not available' do
7272
RestClient.stubs(:put).returns( {failed: -200}.to_json )
7373
expect {
74-
Mothership.change_nickname('MacGyver', 'MacG')
75-
}.to raise_error(Mothership::NicknameUnavailable)
74+
DiscourseHub.change_nickname('MacGyver', 'MacG')
75+
}.to raise_error(DiscourseHub::NicknameUnavailable)
7676
end
7777

78-
# TODO: General error handling in mothership.rb
7978

8079
# it 'should return raise NicknameUnavailable when nickname does not belong to this forum' do
8180
# RestClient.stubs(:put).returns( {failed: -13}.to_json )
8281
# expect {
83-
# Mothership.change_nickname('MacGyver', 'MacG')
84-
# }.to raise_error(Mothership::ActionForbidden)
82+
# DiscourseHub.change_nickname('MacGyver', 'MacG')
83+
# }.to raise_error(DiscourseHub::ActionForbidden)
8584
# end
8685

8786
# it 'should return raise NicknameUnavailable when nickname does not belong to this forum' do
8887
# RestClient.stubs(:put).returns( {failed: -13}.to_json )
8988
# expect {
90-
# Mothership.change_nickname('MacGyver', 'MacG')
91-
# }.to raise_error(Mothership::ActionForbidden)
89+
# DiscourseHub.change_nickname('MacGyver', 'MacG')
90+
# }.to raise_error(DiscourseHub::ActionForbidden)
9291
# end
9392
end
9493
end

0 commit comments

Comments
 (0)