Skip to content

Commit

Permalink
adding users to projects, without auth(cancan) yet
Browse files Browse the repository at this point in the history
  • Loading branch information
2easy committed Mar 19, 2011
1 parent bf4230a commit 07dc6cd
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
15 changes: 15 additions & 0 deletions app/controllers/project_users_controller.rb
@@ -1,5 +1,20 @@
class ProjectUsersController < ApplicationController
def new
@project = Project.find(params[:project_id])
@project_user = ProjectUser.new
@project_user.project_id = params[:project_id]
end
def create
@project_user = ProjectUser.new
@project_user.project_id = params[:project_id]
user = User.find_by_email(params[:project_user][:email])
@project_user.user_id = user.id if user
if @project_user.save
redirect_to project_path(params[:project_id])
else
render :new, flash[:errors] << t('project_users.actions.add_user.failed')

end
end
def destroy
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/project_user.rb
@@ -1,4 +1,9 @@
class ProjectUser < ActiveRecord::Base
belongs_to :project
belongs_to :user

validates_presence_of :project_id, :user_id

def email
end
end
7 changes: 7 additions & 0 deletions app/views/project_users/new.html.haml
@@ -0,0 +1,7 @@
%p= @project.name
%p= t('projects.add_user')

= form_for @project_user do |f|
= f.label :email, t('activerecord.attributes.user.email')
= f.text_field :email
= f.submit t('projects.add_user')
5 changes: 5 additions & 0 deletions app/views/projects/show.html.haml
@@ -1,5 +1,10 @@
%h2= "Project #{@project.name}"
%p= "Api Token: #{@project.api_token}"
%p= t('projects.watchers')
%ul
- @project.users.each do |watcher|
%li= watcher.email
%p= link_to t('projects.add_user'), new_project_user_path(:project_id => @project.id)
%p
%b Issues:
- @project.issues.each do |issue|
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.yml
Expand Up @@ -20,6 +20,7 @@ en:
delete: Delete
save: Save project
add_user: Add user
watchers: Watchers
actions:
destroy:
successful: Project was successfully destroyed
Expand All @@ -32,6 +33,11 @@ en:
new: New user
watchers: Watchers

project_users:
actions:
add_user:
successful: User successfully added as a watcher
failed: Cannot add user as a watcher
sign_in: Sign in
sign_out: Sign out
sign_up: Sign up
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -12,7 +12,7 @@
devise_for :users

resources :projects do
resources :users, :controller => "project_user"
resources :users, :controller => "project_users"
end

resources :projects do
Expand Down
6 changes: 2 additions & 4 deletions spec/acceptance/projects_spec.rb
Expand Up @@ -90,18 +90,16 @@
end

scenario "owner should be able to add/remove watcher to/from the project" do
pending("will do it in a moment")
@bob = @website.has(:user)
@user.visit(project_path(@project))
@user.should_see_translated('projects.add_user')
@user.click_translated('projects.add_user')
@user.should_see(@project.name)
@user.should_see_translated('user.email')
@user.fill_in("user_email", :with => @bob.email)
@user.should_see_translated('activerecord.attributes.user.email')
@user.fill_in("project_user_email", :with => @bob.email)
@user.click_translated('projects.add_user')
@user.should_see(@project.name, @bob.email)
@user.should_see_translated('users.watchers')
@user.click(@bob.email)
end
end
end
Expand Down

0 comments on commit 07dc6cd

Please sign in to comment.