Role system to replace the yml admins and community spotlight. we can
also now add a beta role
This commit is contained in:
parent
562e6641e1
commit
592a3f99b5
12 changed files with 131 additions and 15 deletions
56
app/assets/stylesheets/scaffolds.css.scss
Normal file
56
app/assets/stylesheets/scaffolds.css.scss
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
body {
|
||||
background-color: #fff;
|
||||
color: #333;
|
||||
font-family: verdana, arial, helvetica, sans-serif;
|
||||
font-size: 13px;
|
||||
line-height: 18px; }
|
||||
|
||||
p, ol, ul, td {
|
||||
font-family: verdana, arial, helvetica, sans-serif;
|
||||
font-size: 13px;
|
||||
line-height: 18px; }
|
||||
|
||||
pre {
|
||||
background-color: #eee;
|
||||
padding: 10px;
|
||||
font-size: 11px; }
|
||||
|
||||
a {
|
||||
color: #000;
|
||||
&:visited {
|
||||
color: #666; }
|
||||
&:hover {
|
||||
color: #fff;
|
||||
background-color: #000; } }
|
||||
|
||||
div {
|
||||
&.field, &.actions {
|
||||
margin-bottom: 10px; } }
|
||||
|
||||
#notice {
|
||||
color: green; }
|
||||
|
||||
.field_with_errors {
|
||||
padding: 2px;
|
||||
background-color: red;
|
||||
display: table; }
|
||||
|
||||
#error_explanation {
|
||||
width: 450px;
|
||||
border: 2px solid red;
|
||||
padding: 7px;
|
||||
padding-bottom: 0;
|
||||
margin-bottom: 20px;
|
||||
background-color: #f0f0f0;
|
||||
h2 {
|
||||
text-align: left;
|
||||
font-weight: bold;
|
||||
padding: 5px 5px 5px 15px;
|
||||
font-size: 12px;
|
||||
margin: -7px;
|
||||
margin-bottom: 0px;
|
||||
background-color: #c00;
|
||||
color: #fff; }
|
||||
ul li {
|
||||
font-size: 12px;
|
||||
list-style: square; } }
|
||||
|
|
@ -103,7 +103,7 @@ class AccountDeleter
|
|||
end
|
||||
|
||||
def normal_ar_person_associates_to_delete
|
||||
[:posts, :photos, :mentions, :participations]
|
||||
[:posts, :photos, :mentions, :participations, :roles]
|
||||
end
|
||||
|
||||
def ignored_or_special_ar_person_associations
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ class Person < ActiveRecord::Base
|
|||
accepts_nested_attributes_for :profile
|
||||
|
||||
before_validation :downcase_diaspora_handle
|
||||
|
||||
def downcase_diaspora_handle
|
||||
diaspora_handle.downcase! unless diaspora_handle.blank?
|
||||
end
|
||||
|
|
@ -46,6 +47,8 @@ class Person < ActiveRecord::Base
|
|||
has_many :comments, :foreign_key => :author_id, :dependent => :destroy # This person's own comments
|
||||
has_many :participations, :foreign_key => :author_id, :dependent => :destroy
|
||||
|
||||
has_many :roles
|
||||
|
||||
belongs_to :owner, :class_name => 'User'
|
||||
|
||||
has_many :notification_actors
|
||||
|
|
@ -88,7 +91,7 @@ class Person < ActiveRecord::Base
|
|||
}
|
||||
|
||||
def self.community_spotlight
|
||||
AppConfig[:community_spotlight].present? ? Person.where(:diaspora_handle => AppConfig[:community_spotlight]) : []
|
||||
Person.joins(:roles).where(:roles => {:name => 'spotlight'})
|
||||
end
|
||||
|
||||
# Set a default of an empty profile when a new Person record is instantiated.
|
||||
|
|
|
|||
36
app/models/role.rb
Normal file
36
app/models/role.rb
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#NOTE add the person object you want to attach role to...
|
||||
class Role < ActiveRecord::Base
|
||||
belongs_to :person
|
||||
|
||||
def self.is_admin?(person)
|
||||
find_by_person_id_and_name(person.id, 'admin')
|
||||
end
|
||||
|
||||
def self.add_beta(person)
|
||||
find_or_create_by_person_id_and_name(person.id, 'beta')
|
||||
end
|
||||
|
||||
def self.add_admin(person)
|
||||
find_or_create_by_person_id_and_name(person.id, 'admin')
|
||||
end
|
||||
|
||||
def self.add_spotlight(person)
|
||||
find_or_create_by_person_id_and_name(person.id, 'spotlight')
|
||||
end
|
||||
|
||||
def self.load_admins
|
||||
admins = AppConfig[:admins] || []
|
||||
admins.each do |username|
|
||||
u = User.find_by_username(username)
|
||||
find_or_create_by_person_id_and_name(u.person.id, 'admin')
|
||||
end
|
||||
end
|
||||
|
||||
def self.load_spotlight
|
||||
spotlighters = AppConfig[:community_spotlight] || []
|
||||
spotlighters.each do |diaspora_handle|
|
||||
person = Person.find_by_diaspora_handle(diaspora_handle)
|
||||
find_or_create_by_person_id_and_name(person.id, 'spotlight')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -430,9 +430,10 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def admin?
|
||||
AppConfig[:admins].present? && AppConfig[:admins].include?(self.username)
|
||||
Role.is_admin?(self.person)
|
||||
end
|
||||
|
||||
|
||||
def guard_unconfirmed_email
|
||||
self.unconfirmed_email = nil if unconfirmed_email.blank? || unconfirmed_email == email
|
||||
|
||||
|
|
|
|||
10
db/migrate/20120427152648_create_roles.rb
Normal file
10
db/migrate/20120427152648_create_roles.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
class CreateRoles < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :roles do |t|
|
||||
t.integer :person_id
|
||||
t.string :name
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20120422072257) do
|
||||
ActiveRecord::Schema.define(:version => 20120427152648) do
|
||||
|
||||
create_table "account_deletions", :force => true do |t|
|
||||
t.string "diaspora_handle"
|
||||
|
|
@ -388,6 +388,13 @@ ActiveRecord::Schema.define(:version => 20120422072257) do
|
|||
|
||||
add_index "rails_admin_histories", ["item", "table", "month", "year"], :name => "index_rails_admin_histories"
|
||||
|
||||
create_table "roles", :force => true do |t|
|
||||
t.integer "person_id"
|
||||
t.string "name"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "service_users", :force => true do |t|
|
||||
t.string "uid", :null => false
|
||||
t.string "name", :null => false
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ describe AdminsController do
|
|||
|
||||
context 'admin signed in' do
|
||||
before do
|
||||
AppConfig[:admins] = [@user.username]
|
||||
Role.add_admin(@user.person)
|
||||
end
|
||||
|
||||
it 'succeeds and renders user_search' do
|
||||
|
|
@ -70,7 +70,7 @@ describe AdminsController do
|
|||
|
||||
context 'admin signed in' do
|
||||
before do
|
||||
AppConfig[:admins] = [@user.username]
|
||||
Role.add_admin(@user.person)
|
||||
end
|
||||
|
||||
it 'does not die if you do it twice' do
|
||||
|
|
@ -90,7 +90,7 @@ describe AdminsController do
|
|||
|
||||
describe '#stats' do
|
||||
before do
|
||||
AppConfig[:admins] = [@user.username]
|
||||
Role.add_admin(@user.person)
|
||||
end
|
||||
|
||||
it 'succeeds and renders stats' do
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ describe ContactsController do
|
|||
end
|
||||
|
||||
it 'gets queries for users in the app config' do
|
||||
AppConfig[:community_spotlight] = [alice.diaspora_handle]
|
||||
Role.add_spotlight(alice.person)
|
||||
|
||||
get :spotlight
|
||||
assigns[:people].should == [alice.person]
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ describe StreamsController do
|
|||
|
||||
describe "#public" do
|
||||
it 'will succeed if admin' do
|
||||
AppConfig[:admins] = [alice.username]
|
||||
Role.add_admin(alice.person)
|
||||
get :public
|
||||
response.should be_success
|
||||
end
|
||||
|
|
|
|||
|
|
@ -476,13 +476,11 @@ describe Person do
|
|||
|
||||
describe '.community_spotlight' do
|
||||
describe "when the pod owner hasn't set up any community spotlight members" do
|
||||
before do
|
||||
@existing_community_spotlight = AppConfig[:community_spotlight]
|
||||
AppConfig[:community_spotlight] = nil
|
||||
end
|
||||
after do
|
||||
AppConfig[:community_spotlight] = @existing_community_spotlight
|
||||
it 'returns people with the community spotlight role' do
|
||||
Role.add_spotlight(bob.person)
|
||||
Person.community_spotlight.should be_present
|
||||
end
|
||||
|
||||
it "returns an empty array" do
|
||||
Person.community_spotlight.should == []
|
||||
end
|
||||
|
|
|
|||
5
spec/models/role_spec.rb
Normal file
5
spec/models/role_spec.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Role do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Loading…
Reference in a new issue