Skip to content

Commit 5690a56

Browse files
author
Tony Guntharp
committedFeb 27, 2013
Merge pull request #129 from gabceb/kandan_128
Added check to make sure the # of rooms is respected when adding more rooms
2 parents b0c0669 + 9d94081 commit 5690a56

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed
 

‎app/assets/javascripts/backbone/views/channel_tabs.js.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class Kandan.Views.ChannelTabs extends Backbone.View
3333
success: (model)->
3434
Kandan.Helpers.Channels.createChannelArea(model)
3535

36-
error: (model)->
37-
alert("Something went wrong while creating a new Room.\n\nMaybe the room name is already taken?")
36+
error: (model, response)->
37+
_.each(JSON.parse(response.responseText), alert);
3838
})
3939
console.log "create channel: #{channelName}"
4040
return false

‎app/models/channel.rb

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ class Channel < ActiveRecord::Base
22
has_many :activities, :dependent => :destroy
33
has_many :attachments, :dependent => :destroy
44

5-
validates :name, :presence => true, :uniqueness => true
5+
validates :name, :presence => { :message => "Room name cannot be blank"}, :uniqueness => { :message => "Room name is already taken" }
6+
7+
before_create :ensure_app_max_rooms
8+
9+
def ensure_app_max_rooms
10+
valid = Setting.my_settings.max_rooms > Channel.count
11+
12+
self.errors.add(:max_rooms, "This app has reached the maximum number of rooms") unless valid
13+
14+
valid
15+
end
616

717
class << self
818
def user_connect(user)

‎app/models/setting.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def ensure_only_one_settings
2828

2929
# Making sure the max_rooms is an integer and is never less than the current number of rooms
3030
def validate_max_rooms
31-
self.values[:max_rooms].is_a?(Integer) && self.values[:max_rooms] >= Channel.count unless self.new_record?
31+
self.values[:max_rooms].is_a?(Integer) && self.values[:max_rooms] > 0 && self.values[:max_rooms] >= Channel.count unless self.new_record?
3232
end
3333

3434
# Making sure the public site is a boolean

0 commit comments

Comments
 (0)
Please sign in to comment.