-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manage and display members (#8) #74
Changes from 21 commits
b339e19
0c5d6d5
7213be9
bc4aa11
6c82fd2
f575d2f
c62ab25
9be67b4
1cce2a2
da54a56
df2a000
8c230e8
e5e238c
df1e158
0cdfefd
7cfabff
998e42b
320bddf
0c66608
b89b768
d1921fe
112e032
4414ea5
3d529b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Admin | ||
class MembersController < Admin::ApplicationController | ||
# To customize the behavior of this controller, | ||
# simply overwrite any of the RESTful actions. For example: | ||
# | ||
# def index | ||
# super | ||
# @resources = Member.all.paginate(10, params[:page]) | ||
# end | ||
|
||
# Define a custom finder by overriding the `find_resource` method: | ||
# def find_resource(param) | ||
# Member.find_by!(slug: param) | ||
# end | ||
|
||
# See https://administrate-docs.herokuapp.com/customizing_controller_actions | ||
# for more information | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Admin | ||
class UsersController < Admin::ApplicationController | ||
# To customize the behavior of this controller, | ||
# simply overwrite any of the RESTful actions. For example: | ||
# | ||
# def index | ||
# super | ||
# @resources = Member.all.paginate(10, params[:page]) | ||
# end | ||
|
||
# Define a custom finder by overriding the `find_resource` method: | ||
# def find_resource(param) | ||
# Member.find_by!(slug: param) | ||
# end | ||
|
||
# See https://administrate-docs.herokuapp.com/customizing_controller_actions | ||
# for more information | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require "administrate/base_dashboard" | ||
|
||
class MemberDashboard < Administrate::BaseDashboard | ||
# ATTRIBUTE_TYPES | ||
# a hash that describes the type of each of the model's fields. | ||
# | ||
# Each different type represents an Administrate::Field object, | ||
# which determines how the attribute is displayed | ||
# on pages throughout the dashboard. | ||
ATTRIBUTE_TYPES = { | ||
events: Field::HasMany, | ||
organizations: Field::HasMany, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After playing around to understand administrate and that bug: https://github.com/montrealrb/Montreal.rb/pull/74/files#r47185636 I found out that removing all references in the dashboard to events and organizations for now fixes it. |
||
user: Field::BelongsTo, | ||
id: Field::Number, | ||
name: Field::String, | ||
email: Field::String, | ||
picture: Field::String.with_options(searchable: false), | ||
twitter_handle: Field::String, | ||
github_handle: Field::String, | ||
biography: Field::Text, | ||
created_at: Field::DateTime, | ||
updated_at: Field::DateTime, | ||
}.freeze | ||
|
||
# COLLECTION_ATTRIBUTES | ||
# an array of attributes that will be displayed on the model's index page. | ||
# | ||
# By default, it's limited to four items to reduce clutter on index pages. | ||
# Feel free to add, remove, or rearrange items. | ||
COLLECTION_ATTRIBUTES = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Freeze mutable objects assigned to constants. |
||
:user, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After removing Also, to be able to display There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're a bit confused. We should replace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coaxial, please:
|
||
:id, | ||
].freeze | ||
|
||
# SHOW_PAGE_ATTRIBUTES | ||
# an array of attributes that will be displayed on the model's show page. | ||
SHOW_PAGE_ATTRIBUTES = ATTRIBUTE_TYPES.keys | ||
|
||
# FORM_ATTRIBUTES | ||
# an array of attributes that will be displayed | ||
# on the model's form (`new` and `edit`) pages. | ||
FORM_ATTRIBUTES = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Freeze mutable objects assigned to constants. |
||
:user, | ||
:name, | ||
:email, | ||
:picture, | ||
:twitter_handle, | ||
:github_handle, | ||
:biography, | ||
].freeze | ||
|
||
# Overwrite this method to customize how members are displayed | ||
# across all pages of the admin dashboard. | ||
# | ||
# def display_resource(member) | ||
# "Member ##{member.id}" | ||
# end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,21 +8,9 @@ class UserDashboard < Administrate::BaseDashboard | |
# which determines how the attribute is displayed | ||
# on pages throughout the dashboard. | ||
ATTRIBUTE_TYPES = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Freeze mutable objects assigned to constants. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Freeze mutable objects assigned to constants. |
||
votes: Field::HasMany, | ||
id: Field::Number, | ||
email: Field::String, | ||
encrypted_password: Field::String, | ||
reset_password_token: Field::String, | ||
reset_password_sent_at: Field::DateTime, | ||
remember_created_at: Field::DateTime, | ||
sign_in_count: Field::Number, | ||
current_sign_in_at: Field::DateTime, | ||
last_sign_in_at: Field::DateTime, | ||
current_sign_in_ip: Field::String.with_options(searchable: false), | ||
last_sign_in_ip: Field::String.with_options(searchable: false), | ||
created_at: Field::DateTime, | ||
updated_at: Field::DateTime, | ||
bio: Field::String | ||
member: Field::HasOne, | ||
}.freeze | ||
|
||
# COLLECTION_ATTRIBUTES | ||
|
@@ -31,10 +19,9 @@ class UserDashboard < Administrate::BaseDashboard | |
# By default, it's limited to four items to reduce clutter on index pages. | ||
# Feel free to add, remove, or rearrange items. | ||
COLLECTION_ATTRIBUTES = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Freeze mutable objects assigned to constants. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Freeze mutable objects assigned to constants. |
||
:votes, | ||
:id, | ||
:email, | ||
:encrypted_password | ||
:member, | ||
].freeze | ||
|
||
# SHOW_PAGE_ATTRIBUTES | ||
|
@@ -45,18 +32,7 @@ class UserDashboard < Administrate::BaseDashboard | |
# an array of attributes that will be displayed | ||
# on the model's form (`new` and `edit`) pages. | ||
FORM_ATTRIBUTES = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Freeze mutable objects assigned to constants. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Freeze mutable objects assigned to constants. |
||
:votes, | ||
:email, | ||
:encrypted_password, | ||
:reset_password_token, | ||
:reset_password_sent_at, | ||
:remember_created_at, | ||
:sign_in_count, | ||
:current_sign_in_at, | ||
:last_sign_in_at, | ||
:current_sign_in_ip, | ||
:last_sign_in_ip, | ||
:bio | ||
].freeze | ||
|
||
# Overwrite this method to customize how users are displayed | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Member < ActiveRecord::Base | ||
has_and_belongs_to_many :events | ||
has_and_belongs_to_many :organizations | ||
belongs_to :user | ||
|
||
validates :name, :email, presence: true | ||
validates :email, uniqueness: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ class User < ActiveRecord::Base | |
:recoverable, :rememberable, :trackable, :validatable, | ||
:omniauthable, omniauth_providers: [:github] | ||
|
||
has_one :member | ||
|
||
def self.from_omniauth(auth) | ||
where(provider: auth.provider, uid: auth.uid).first_or_create do |user| | ||
user.email = auth.info.email | ||
|
@@ -53,4 +55,5 @@ def self.default_user | |
def active_for_authentication? | ||
super && email != DEFAULT_USER_EMAIL | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at class body end. |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateMembers < ActiveRecord::Migration | ||
def change | ||
create_table :members do |t| | ||
t.string :name | ||
t.string :email | ||
t.binary :picture | ||
t.string :twitter_handle | ||
t.string :github_handle | ||
t.text :biography | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddNullConstraintToEmail < ActiveRecord::Migration | ||
def change | ||
change_column_null :members, :email, false | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddForeignKeyToUsers < ActiveRecord::Migration | ||
def change | ||
add_column :users, :member_id, :integer | ||
add_foreign_key :users, :members | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class RemoveForeignKeyFromUsers < ActiveRecord::Migration | ||
def change | ||
remove_foreign_key :users, :members | ||
remove_column :users, :member_id | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddForeignKeyToMembers < ActiveRecord::Migration | ||
def change | ||
add_column :members, :user_id, :integer | ||
add_foreign_key :members, :users | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class CreateHabtmRelationshipBetweenMembersAndEvents < ActiveRecord::Migration | ||
def change | ||
create_table :events_members do |t| | ||
t.belongs_to :event, index: true | ||
t.belongs_to :member, index: true | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class HabtmRelationshipBetweenMembersAndOrganization < ActiveRecord::Migration | ||
def change | ||
create_table :members_organizations do |t| | ||
t.belongs_to :organization, index: true | ||
t.belongs_to :member, index: true | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FactoryGirl.define do | ||
factory :member do | ||
name "MyString" | ||
email "MyString" | ||
picture "" | ||
twitter_handle "MyString" | ||
github_handle "MyString" | ||
biography "MyText" | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ca we correct indentation here please? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Member, type: :model do | ||
context "without a name" do | ||
it "should be invalid" do | ||
member = Member.new | ||
|
||
member.email = "gala@example.com" | ||
|
||
expect(member).to be_invalid | ||
end | ||
end | ||
|
||
context "without an email" do | ||
it "should be invalid" do | ||
member = Member.new | ||
|
||
member.name = "Zaba" | ||
|
||
expect(member).to be_invalid | ||
end | ||
end | ||
|
||
context "with a duplicate email" do | ||
it "should be invalid" do | ||
member1 = Member.new | ||
member1.name = "Zaba" | ||
member1.email = "gala@example.com" | ||
|
||
member2 = Member.new | ||
member2.name = "Gala" | ||
member2.email = "gala@example.com" | ||
|
||
member1.save | ||
|
||
expect(member2).to be_invalid | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze mutable objects assigned to constants.