mirror of
https://github.com/wahyd4/ocelots.git
synced 2026-08-09 04:56:21 +10:00
added creator to team and removed restrictions on team creation and updates (everyone can create teams and any member of a team can add new members)
This commit is contained in:
@@ -5,22 +5,22 @@ class TeamsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
if current_person.blessed?
|
||||
team = Team.create params[:team]
|
||||
redirect_to "/teams/#{team.slug}"
|
||||
@teams = current_person.teams
|
||||
@team = Team.new params[:team].merge creator: current_person
|
||||
if @team.save
|
||||
redirect_to "/teams/#{@team.slug}"
|
||||
else
|
||||
redirect_to :teams
|
||||
render :index
|
||||
end
|
||||
end
|
||||
|
||||
def add
|
||||
if current_person.blessed?
|
||||
team = Team.find_by_slug params[:slug]
|
||||
with_team do |team|
|
||||
person = Person.find_by_email params[:email]
|
||||
person = Person.create email: params[:email] unless person
|
||||
Membership.create team: team, person: person
|
||||
redirect_to "/teams/#{team.slug}"
|
||||
end
|
||||
redirect_to "/teams/#{team.slug}"
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -43,7 +43,7 @@ private
|
||||
def with_team *args
|
||||
@team = Team.find_by_slug params[:slug]
|
||||
unless current_person.blessed?
|
||||
@team = nil unless current_person.teams.include? @team
|
||||
@team = nil unless current_person.teams.include?(@team) or @team.creator == current_person
|
||||
end
|
||||
if @team
|
||||
yield @team
|
||||
|
||||
+7
-2
@@ -1,6 +1,11 @@
|
||||
class Team < ActiveRecord::Base
|
||||
attr_accessible :description, :name, :slug
|
||||
attr_accessible :description, :name, :slug, :creator
|
||||
|
||||
validates_presence_of :name
|
||||
validates_presence_of :slug
|
||||
validates_uniqueness_of :slug
|
||||
|
||||
has_many :memberships
|
||||
has_many :people, through: :memberships
|
||||
end
|
||||
belongs_to :creator, class_name: 'Person'
|
||||
end
|
||||
@@ -1,10 +1,9 @@
|
||||
- if @person.blessed?
|
||||
div.row
|
||||
div.offset3
|
||||
= form_for @team, html: {class: 'form-inline'} do |form|
|
||||
= form.text_field :slug, placeholder: 'slug'
|
||||
= form.text_field :name, placeholder: 'Team Name'
|
||||
= form.submit 'Create', class: 'btn'
|
||||
div.row
|
||||
div.offset3
|
||||
= form_for @team, html: {class: 'form-inline'} do |form|
|
||||
= form.text_field :slug, placeholder: 'slug'
|
||||
= form.text_field :name, placeholder: 'Team Name'
|
||||
= form.submit 'Create', class: 'btn'
|
||||
|
||||
- @teams.each do |team|
|
||||
a href="/teams/#{team.slug}"
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
li
|
||||
= link_to 'quiz', "/quiz/#{@team.slug}"
|
||||
|
||||
- if @person.blessed?
|
||||
div.row
|
||||
div.offset3
|
||||
= form_tag "/teams/#{@team.slug}/add", class: 'form-inline' do
|
||||
= text_field_tag :email, nil, placeholder: 'email'
|
||||
= submit_tag 'add', class: 'btn'
|
||||
div.row
|
||||
div.offset3
|
||||
= form_tag "/teams/#{@team.slug}/add", class: 'form-inline' do
|
||||
= text_field_tag :email, nil, placeholder: 'email'
|
||||
= submit_tag 'add', class: 'btn'
|
||||
|
||||
- @team.memberships.each do |membership|
|
||||
div.hero-unit
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddCreatorToTeam < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :teams, :creator_id, :integer
|
||||
end
|
||||
end
|
||||
+2
-1
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20120901061532) do
|
||||
ActiveRecord::Schema.define(:version => 20120902015738) do
|
||||
|
||||
create_table "facts", :force => true do |t|
|
||||
t.integer "person_id"
|
||||
@@ -54,6 +54,7 @@ ActiveRecord::Schema.define(:version => 20120901061532) do
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "slug"
|
||||
t.integer "creator_id"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user