Commit af16f4c9d8bee8cec455c81d9518971a93116750

Authored by João M. M. Silva
Committed by Rafael Manzo
1 parent 4a6a1c2e

Verification if user is logged in to operate with projects

Missing fix tests that must get an authenticated user to run
app/controllers/projects_controller.rb
1 1 class ProjectsController < ApplicationController
  2 + before_filter :authenticate_user!,
  3 + except: [:index, :show]
2 4  
3 5 # GET /projects/new
4 6 def new
... ... @@ -15,9 +17,10 @@ class ProjectsController &lt; ApplicationController
15 17 # POST /projects.json
16 18 def create
17 19 @project = Project.new(project_params)
18   -
19 20 respond_to do |format|
20 21 if @project.save
  22 + current_user.project_ownerships.create project_id: @project.id
  23 +
21 24 format.html { redirect_to project_path(@project.id), notice: 'Project was successfully created.' }
22 25 format.json { render action: 'show', status: :created, location: @project }
23 26 else
... ... @@ -32,7 +35,7 @@ class ProjectsController &lt; ApplicationController
32 35 def show
33 36 set_project
34 37 end
35   -
  38 +
36 39 # GET /projects/1/edit
37 40 # GET /projects/1/edit.json
38 41 def edit
... ... @@ -52,6 +55,7 @@ class ProjectsController &lt; ApplicationController
52 55 # DELETE /project/1.json
53 56 def destroy
54 57 set_project
  58 + current_user.project_ownerships.find_by_project_id(@project.id).destroy
55 59 @project.destroy
56 60 respond_to do |format|
57 61 format.html { redirect_to projects_url }
... ...
app/models/project_ownership.rb
1 1 class ProjectOwnership < ActiveRecord::Base
2 2 belongs_to :user
  3 + validates :project_id, presence: true
3 4 end
... ...