From 6be38bc3b6ee5546c0d1f26497c2687b4138df35 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 6 Apr 2014 13:58:56 -0400 Subject: User.permission_bits: return 2^n instead of n for each. This way they can easily be ORed together, C-like. --- app/models/user.rb | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'app/models') diff --git a/app/models/user.rb b/app/models/user.rb index 626e4bf..0b77ab1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,31 +11,32 @@ class User < ActiveRecord::Base def self.permission_bits return { - :create_tournament => 1, - :edit_tournament => 2, - :join_tournament => 3, - :delete_tournament => 4, + :create_tournament => (2**1), + :edit_tournament => (2**2), + :join_tournament => (2**3), + :delete_tournament => (2**4), - :create_game => 5, - :edit_game => 6, - :delete_game => 7, + :create_game => (2**5), + :edit_game => (2**6), + :delete_game => (2**7), - :create_user => 8, - :edit_user => 9, - :delete_user => 10, + :create_user => (2**8), + :edit_user => (2**9), + :delete_user => (2**10), - :create_alert => 11, - :edit_alert => 12, - :delete_alert => 13, + :create_alert => (2**11), + :edit_alert => (2**12), + :delete_alert => (2**13), - :create_pm => 14, - :edit_pm => 15, - :delete_pm => 16, + :create_pm => (2**14), + :edit_pm => (2**15), + :delete_pm => (2**16), - :create_session => 17, - :delete_session => 18, + :create_session => (2**17), + :delete_session => (2**18), - :edit_permissions => 19, + :edit_permissions => (2**19), + :edit_server => (2**20), } end @@ -44,21 +45,21 @@ class User < ActiveRecord::Base if bit.nil? return false else - return (self.permissions & (2**bit) != 0) + return (self.permissions & bit != 0) end end def add_ability(action) bit = User.permission_bits[action.to_sym] unless bit.nil? - self.permissions |= 2**bit + self.permissions |= bit end end def remove_ability(action) bit = User.permission_bits[action.to_sym] unless bit.nil? - self.permissions &= ~ (2**bit) + self.permissions &= ~ bit end end -- cgit v1.2.3-2-g168b From cfaff7870d0348b25b3b4b2597950894ab25d989 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 6 Apr 2014 14:32:38 -0400 Subject: implement editing the default user permissions --- app/models/server.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'app/models') diff --git a/app/models/server.rb b/app/models/server.rb index 120f0fa..5ba7524 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -1,2 +1,38 @@ class Server < ActiveRecord::Base + def default_user_abilities + @abilities ||= User::Abilities.new(DefaultUser.new(self)) + end + def default_user_abilities=(new) + new.each do |k,v| + if v == "0" + v = false + end + default_user_abilities[k] = v + end + end + class DefaultUser + def initialize(server) + @server = server + end + def can?(action) + bit = User.permission_bits[action] + if bit.nil? + return false + else + return (@server.default_user_permissions & bit != 0) + end + end + def add_ability(action) + bit = User.permission_bits[action.to_sym] + unless bit.nil? + @server.default_user_permissions |= bit + end + end + def remove_ability(action) + bit = User.permission_bits[action.to_sym] + unless bit.nil? + @server.default_user_permissions &= ~ bit + end + end + end end -- cgit v1.2.3-2-g168b From f85943114dba527a1f87abb03229553472f57c0c Mon Sep 17 00:00:00 2001 From: tkimia Date: Sun, 6 Apr 2014 18:45:41 -0400 Subject: started SVG generation --- app/models/tournament.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/tournament.rb b/app/models/tournament.rb index e408cfe..0029de7 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -31,7 +31,7 @@ class Tournament < ActiveRecord::Base for i in 1..num_matches self.matches.create(name: "Match #{i}", status: 0) end - match_num = 0 + match_num = num_matches-1 team_num = 0 #for each grouping of min_players_per_team self.players.each_slice(min_players_per_team) do |players| @@ -39,7 +39,7 @@ class Tournament < ActiveRecord::Base self.matches[match_num].teams.push(Team.create(users: players)) #if the match is full, move to the next match, otherwise move to the next team if (team_num != 0 and team_num % max_teams_per_match == 0) - match_num += 1 + match_num -= 1 team_num = 0 else team_num += 1 -- cgit v1.2.3-2-g168b From 0f982ba511d4f38322f69a6aaed768181b4e2852 Mon Sep 17 00:00:00 2001 From: tkimia Date: Sun, 6 Apr 2014 21:10:46 -0400 Subject: some more graphics --- app/models/tournament.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 0029de7..859518c 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -38,7 +38,7 @@ class Tournament < ActiveRecord::Base #create a new team in the current match self.matches[match_num].teams.push(Team.create(users: players)) #if the match is full, move to the next match, otherwise move to the next team - if (team_num != 0 and team_num % max_teams_per_match == 0) + if (team_num > max_teams_per_match) match_num -= 1 team_num = 0 else -- cgit v1.2.3-2-g168b From 5084f01e0ea7ba7c378982099fdbf9880857f091 Mon Sep 17 00:00:00 2001 From: tkimia Date: Sun, 6 Apr 2014 21:52:32 -0400 Subject: matches are given teams correctly --- app/models/tournament.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 859518c..72c3ac8 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -34,16 +34,17 @@ class Tournament < ActiveRecord::Base match_num = num_matches-1 team_num = 0 #for each grouping of min_players_per_team - self.players.each_slice(min_players_per_team) do |players| - #create a new team in the current match - self.matches[match_num].teams.push(Team.create(users: players)) + players.each_slice(min_players_per_team) do |players| + #if the match is full, move to the next match, otherwise move to the next team - if (team_num > max_teams_per_match) + if (team_num == min_teams_per_match) match_num -= 1 team_num = 0 else team_num += 1 end + #create a new team in the current match + self.matches[match_num].teams.push(Team.create(users: players)) end end end -- cgit v1.2.3-2-g168b