@users = User.joins(:roles).where(:user_roles => { :role => "administrator" })
end
- @issues = Issue.where(:issue_type => @user_role)
+ @issues = Issue.where(:assigned_role => @user_role)
# If search
if params[:search_by_user] && params[:search_by_user].present?
@read_reports = @issue.read_reports
@unread_reports = @issue.unread_reports
@comments = @issue.comments
- @related_issues = @issue.reported_user.issues.where(:issue_type => @user_role)
+ @related_issues = @issue.reported_user.issues.where(:assigned_role => @user_role)
@new_comment = IssueComment.new(:issue => @issue)
end
# Reassign Issues between Administrators and Moderators
def reassign_issue
- @issue.issue_type = upgrade_issue(@issue.issue_type)
+ @issue.assigned_role = upgrade_issue(@issue.assigned_role)
@issue.save!
end
# reportable_id :integer not null
# reported_user_id :integer not null
# status :integer
-# issue_type :string
+# assigned_role :enum not null
# resolved_at :datetime
# resolved_by :integer
# updated_by :integer
validates :reportable_id, :uniqueness => { :scope => [:reportable_type] }
validates :reported_user_id, :presence => true
+ before_validation :set_default_assigned_role
before_validation :set_reported_user
# Check if more statuses are needed
reportable.user
end
end
+
+ def set_default_assigned_role
+ role = %w[Changeset Note].include?(reportable.class.name) ? "moderator" : "administrator"
+ self.assigned_role = role if assigned_role.blank?
+ end
end
t.integer :reportable_id, :null => false
t.integer :reported_user_id, :null => false
t.integer :status
- t.string :issue_type
+ t.column :assigned_role, :user_role_enum, :null => false
t.datetime :resolved_at
t.integer :resolved_by
t.integer :updated_by
reportable_id integer NOT NULL,
reported_user_id integer NOT NULL,
status integer,
- issue_type character varying,
+ assigned_role user_role_enum NOT NULL,
resolved_at timestamp without time zone,
resolved_by integer,
updated_by integer,
('7'),
('8'),
('9');
+
+
issue.save!
assert_equal issue.reported_user, diary_entry.user
end
+
+ def test_default_assigned_role
+ create(:language, :code => "en")
+ diary_entry = create(:diary_entry)
+ changeset = create(:changeset)
+
+ issue = Issue.new
+ issue.reportable = diary_entry
+ issue.save!
+ assert_equal "administrator", issue.assigned_role
+
+ issue = Issue.new
+ issue.reportable = changeset
+ issue.save!
+ assert_equal "moderator", issue.assigned_role
+
+ # check the callback doesn't override an explicitly set role
+ issue.assigned_role = "administrator"
+ issue.save!
+ issue.reload
+ assert_equal "administrator", issue.assigned_role
+ end
end
def test_view_issues
sign_in_as(create(:moderator_user))
- issues = create_list(:issue, 3, :issue_type => "moderator")
+ issues = create_list(:issue, 3, :assigned_role => "moderator")
visit issues_path
assert page.has_content?(issues.first.reported_user.display_name)
def test_search_issues_by_user
good_user = create(:user)
bad_user = create(:user)
- create(:issue, :reportable => bad_user, :reported_user => bad_user, :issue_type => "administrator")
+ create(:issue, :reportable => bad_user, :reported_user => bad_user, :assigned_role => "administrator")
sign_in_as(create(:administrator_user))