diff --git a/app/models/badge.rb b/app/models/badge.rb index 9f8cee90209..70e18460836 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -22,6 +22,5 @@ end # # Indexes # -# index_badges_on_badge_type_id (badge_type_id) -# index_badges_on_name (name) UNIQUE +# index_badges_on_name (name) UNIQUE # diff --git a/app/models/category_custom_field.rb b/app/models/category_custom_field.rb index ccc3344ff8b..b66a820f744 100644 --- a/app/models/category_custom_field.rb +++ b/app/models/category_custom_field.rb @@ -6,12 +6,12 @@ end # # Table name: category_custom_fields # -# id :integer not null, primary key -# category_id :integer not null -# name :string(256) not null -# value :text -# created_at :datetime -# updated_at :datetime +# id :integer not null, primary key +# category_id :integer not null +# name :string(256) not null +# value :text +# created_at :datetime +# updated_at :datetime # # Indexes # diff --git a/app/models/color_scheme.rb b/app/models/color_scheme.rb index 1cf058bf454..34731dafb57 100644 --- a/app/models/color_scheme.rb +++ b/app/models/color_scheme.rb @@ -49,3 +49,16 @@ class ColorScheme < ActiveRecord::Base end end + +# == Schema Information +# +# Table name: color_schemes +# +# id :integer not null, primary key +# name :string(255) not null +# enabled :boolean default(FALSE), not null +# versioned_id :integer +# version :integer default(1), not null +# created_at :datetime +# updated_at :datetime +# diff --git a/app/models/color_scheme_color.rb b/app/models/color_scheme_color.rb index 4bcb5b0018d..fe5f0b628c9 100644 --- a/app/models/color_scheme_color.rb +++ b/app/models/color_scheme_color.rb @@ -97,3 +97,20 @@ class ColorSchemeColor < ActiveRecord::Base bookmarkColor: "00aaff" } end + +# == Schema Information +# +# Table name: color_scheme_colors +# +# id :integer not null, primary key +# name :string(255) not null +# hex :string(255) not null +# opacity :integer default(100), not null +# color_scheme_id :integer not null +# created_at :datetime +# updated_at :datetime +# +# Indexes +# +# index_color_scheme_colors_on_color_scheme_id (color_scheme_id) +# diff --git a/app/models/group.rb b/app/models/group.rb index 6bd93a534b4..521d4686331 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -243,6 +243,7 @@ end # automatic :boolean default(FALSE), not null # user_count :integer default(0), not null # alias_level :integer default(0) +# visible :boolean default(TRUE), not null # # Indexes # diff --git a/app/models/group_custom_field.rb b/app/models/group_custom_field.rb index 78b087b97c8..54a8a63b319 100644 --- a/app/models/group_custom_field.rb +++ b/app/models/group_custom_field.rb @@ -6,12 +6,12 @@ end # # Table name: group_custom_fields # -# id :integer not null, primary key -# group_id :integer not null -# name :string(256) not null -# value :text -# created_at :datetime -# updated_at :datetime +# id :integer not null, primary key +# group_id :integer not null +# name :string(256) not null +# value :text +# created_at :datetime +# updated_at :datetime # # Indexes # diff --git a/app/models/invite.rb b/app/models/invite.rb index dd4f29a348f..2736dd4a387 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -5,6 +5,8 @@ class Invite < ActiveRecord::Base belongs_to :topic belongs_to :invited_by, class_name: 'User' + has_many :invited_groups + has_many :groups, through: :invited_groups has_many :topic_invites has_many :topics, through: :topic_invites, source: :topic validates_presence_of :email diff --git a/app/models/invite_redeemer.rb b/app/models/invite_redeemer.rb index e9fe3d37b00..e0c018933be 100644 --- a/app/models/invite_redeemer.rb +++ b/app/models/invite_redeemer.rb @@ -34,6 +34,7 @@ InviteRedeemer = Struct.new(:invite) do def process_invitation add_to_private_topics_if_invited add_user_to_invited_topics + add_user_to_groups send_welcome_message approve_account_if_needed notify_invitee @@ -75,6 +76,12 @@ InviteRedeemer = Struct.new(:invite) do end end + def add_user_to_groups + invite.groups.each do |g| + invited_user.group_users.create(group_id: g.id) + end + end + def send_welcome_message if Invite.where(['email = ?', invite.email]).update_all(['user_id = ?', invited_user.id]) == 1 invited_user.send_welcome_message = true diff --git a/app/models/invited_group.rb b/app/models/invited_group.rb new file mode 100644 index 00000000000..e6bc6845b74 --- /dev/null +++ b/app/models/invited_group.rb @@ -0,0 +1,15 @@ +class InvitedGroup < ActiveRecord::Base + belongs_to :group + belongs_to :invite +end + +# == Schema Information +# +# Table name: invited_groups +# +# id :integer not null, primary key +# group_id :integer +# invite_id :integer +# created_at :datetime +# updated_at :datetime +# diff --git a/app/models/post_custom_field.rb b/app/models/post_custom_field.rb index e7b00105660..8f2bddc75c8 100644 --- a/app/models/post_custom_field.rb +++ b/app/models/post_custom_field.rb @@ -6,12 +6,12 @@ end # # Table name: post_custom_fields # -# id :integer not null, primary key -# post_id :integer not null -# name :string(256) not null -# value :text -# created_at :datetime -# updated_at :datetime +# id :integer not null, primary key +# post_id :integer not null +# name :string(256) not null +# value :text +# created_at :datetime +# updated_at :datetime # # Indexes # diff --git a/app/models/topic_custom_field.rb b/app/models/topic_custom_field.rb index 85db5aea30f..f1663a29379 100644 --- a/app/models/topic_custom_field.rb +++ b/app/models/topic_custom_field.rb @@ -6,12 +6,12 @@ end # # Table name: topic_custom_fields # -# id :integer not null, primary key -# topic_id :integer not null -# name :string(256) not null -# value :text -# created_at :datetime -# updated_at :datetime +# id :integer not null, primary key +# topic_id :integer not null +# name :string(256) not null +# value :text +# created_at :datetime +# updated_at :datetime # # Indexes # diff --git a/app/models/user.rb b/app/models/user.rb index 30daf56752b..9eae13b2b49 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -777,6 +777,9 @@ end # primary_group_id :integer # locale :string(10) # profile_background :string(255) +# email_hash :string(255) +# registration_ip_address :inet +# last_redirected_to_top_at :datetime # # Indexes # diff --git a/db/migrate/20140508053815_add_invited_groups.rb b/db/migrate/20140508053815_add_invited_groups.rb new file mode 100644 index 00000000000..09a51ee1ac9 --- /dev/null +++ b/db/migrate/20140508053815_add_invited_groups.rb @@ -0,0 +1,9 @@ +class AddInvitedGroups < ActiveRecord::Migration + def change + create_table :invited_groups do |t| + t.integer :group_id + t.integer :invite_id + t.timestamps + end + end +end diff --git a/spec/models/invite_spec.rb b/spec/models/invite_spec.rb index 0cf6dbb5bf1..9d52af523f9 100644 --- a/spec/models/invite_spec.rb +++ b/spec/models/invite_spec.rb @@ -2,10 +2,6 @@ require 'spec_helper' describe Invite do - it { should belong_to :user } - it { should have_many :topic_invites } - it { should belong_to :invited_by } - it { should have_many :topics } it { should validate_presence_of :email } it { should validate_presence_of :invited_by_id } @@ -65,9 +61,6 @@ describe Invite do it 'belongs to the topic' do topic.invites.should == [@invite] - end - - it 'has a topic' do @invite.topics.should == [topic] end @@ -77,27 +70,16 @@ describe Invite do it 'returns a different invite' do new_invite.should_not == @invite - end - - it 'has a different key' do new_invite.invite_key.should_not == @invite.invite_key - end - - it 'has the topic relationship' do new_invite.topics.should == [topic] end + end context 'when adding a duplicate' do it 'returns the original invite' do topic.invite_by_email(inviter, 'iceking@adventuretime.ooo').should == @invite - end - - it 'matches case insensitively for the domain part' do topic.invite_by_email(inviter, 'iceking@ADVENTURETIME.ooo').should == @invite - end - - it 'matches case sensitively for the local part' do topic.invite_by_email(inviter, 'ICEKING@adventuretime.ooo').should_not == @invite end @@ -114,21 +96,13 @@ describe Invite do context 'when adding to another topic' do let!(:another_topic) { Fabricate(:topic, user: topic.user) } - before do - @new_invite = another_topic.invite_by_email(inviter, iceking) - end - it 'should be the same invite' do + @new_invite = another_topic.invite_by_email(inviter, iceking) @new_invite.should == @invite - end - - it 'belongs to the new topic' do another_topic.invites.should == [@invite] - end - - it 'has references to both topics' do @invite.topics.should =~ [topic, another_topic] end + end end end @@ -172,7 +146,18 @@ describe Invite do invite.redeem.should be_blank end - context 'invite trust levels' do + context "when inviting to groups" do + it "add the user to the correct groups" do + group = Fabricate(:group) + invite.invited_groups.build(group_id: group.id) + invite.save + + user = invite.redeem + user.groups.count.should == 1 + end + end + + context "invite trust levels" do it "returns the trust level in default_invitee_trust_level" do SiteSetting.stubs(:default_invitee_trust_level).returns(TrustLevel.levels[:leader]) invite.redeem.trust_level.should == TrustLevel.levels[:leader] @@ -183,7 +168,6 @@ describe Invite do it 'correctly activates accounts' do SiteSetting.stubs(:must_approve_users).returns(true) user = invite.redeem - user.approved?.should == true end end @@ -257,13 +241,7 @@ describe Invite do it 'adds the user to the topic_users of the first topic' do topic.allowed_users.include?(user).should be_true - end - - it 'adds the user to the topic_users of the second topic' do another_topic.allowed_users.include?(user).should be_true - end - - it 'does not redeem the second invite' do another_invite.reload another_invite.should_not be_redeemed end @@ -276,9 +254,6 @@ describe Invite do it 'returns the same user' do @result.should == user - end - - it 'marks the second invite as redeemed' do another_invite.reload another_invite.should be_redeemed end @@ -303,7 +278,7 @@ describe Invite do context 'with user that has not invited' do it 'does not return invites' do user = Fabricate(:user) - invite = Fabricate(:invite) + Fabricate(:invite) invites = Invite.find_all_invites_from(user) @@ -315,12 +290,13 @@ describe Invite do describe '.find_redeemed_invites_from' do it 'returns redeemed invites only' do inviter = Fabricate(:user) - pending_invite = Fabricate( + Fabricate( :invite, invited_by: inviter, user_id: nil, email: 'pending@example.com' ) + redeemed_invite = Fabricate( :invite, invited_by: inviter,