From 30564373087a4c78d4133d3a1ffdf262507c10de Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Tue, 20 Oct 2015 18:04:50 +0100 Subject: [PATCH 1/2] Added moderator group --- app/models/group.rb | 1 + app/models/user.rb | 4 ++++ spec/factories/group.rb | 5 +++++ spec/models/user_spec.rb | 12 ++++++++++++ 4 files changed, 22 insertions(+) diff --git a/app/models/group.rb b/app/models/group.rb index 734ea38..367185d 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -21,6 +21,7 @@ class Group < ActiveRecord::Base CHAMPIONS = 7 PREDICTORS = 8 STAFF = 10 + GATHER_MODERATORS = 14 attr_protected :id, :updated_at, :created_at, :founder_id validates_length_of :name, :maximum => 20 diff --git a/app/models/user.rb b/app/models/user.rb index 13d0407..1d28615 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -205,6 +205,10 @@ class User < ActiveRecord::Base groups.exists? :id => Group::CASTERS end + def gather_moderator? + groups.exists? id: Group::GATHER_MODERATORS + end + def verified? # created_at < DateTime.now.ago(VERIFICATION_TIME) true diff --git a/spec/factories/group.rb b/spec/factories/group.rb index bf72ae2..68cec21 100644 --- a/spec/factories/group.rb +++ b/spec/factories/group.rb @@ -19,4 +19,9 @@ FactoryGirl.define do name "Donors" id Group::DONORS end + + trait :gather_moderator do + name "Gather Moderator" + id Group::GATHER_MODERATORS + end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 49f261c..0258344 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -48,4 +48,16 @@ describe User do expect(user.banned? Ban::TYPE_MUTE).to be_truthy end end + + describe "#gather_moderator?" do + let!(:group) { create :group, :gather_moderator } + + it "returns true if gather moderator" do + create :grouper, group: group, user: user + expect(user.gather_moderator?).to eq(true) + end + it "returns false if not gather moderator" do + expect(user.gather_moderator?).to eq(false) + end + end end From 9a88937fafc1cf9e589be5654631866d93ad8c4d Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Tue, 20 Oct 2015 18:11:46 +0100 Subject: [PATCH 2/2] Return moderator status with users api --- app/controllers/api/v1/users_controller.rb | 1 + spec/controllers/api/v1/users_controller_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index accc35f..acbb10e 100755 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -16,6 +16,7 @@ class Api::V1::UsersController < Api::V1::BaseController time_zone: @user.time_zone, avatar: @user.profile.avatar.url, admin: @user.admin?, + moderator: @user.gather_moderator?, steam: @user.steamid.nil? ? nil : { id: @user.steamid, url: @steam.nil? ? nil : @steam.base_url, diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index c2a7059..7bf091e 100755 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -19,6 +19,7 @@ describe Api::V1::UsersController do expect(json["country"]).to eq(@user.country) expect(json["time_zone"]).to eq(@user.time_zone) expect(json["admin"]).to eq(@user.admin?) + expect(json["moderator"]).to eq(@user.gather_moderator?) expect(json).to have_key("steam") expect(json["steam"]).to have_key("id") expect(json["steam"]).to have_key("url") @@ -39,6 +40,13 @@ describe Api::V1::UsersController do expect(json["steam"]).to be_nil end + it "returns gather moderator status" do + group = create :group, :gather_moderator + create :grouper, user: @user, group: group + get :show, id: @user.id + expect(json["moderator"]).to eq(true) + end + it "returns 404 if user does not exist" do expect { get :show, id: -1