Commit af16f4c9d8bee8cec455c81d9518971a93116750
Committed by
Rafael Manzo
1 parent
4a6a1c2e
Exists in
colab
and in
4 other branches
Verification if user is logged in to operate with projects
Missing fix tests that must get an authenticated user to run
Showing
2 changed files
with
7 additions
and
2 deletions
Show diff stats
app/controllers/projects_controller.rb
1 | class ProjectsController < ApplicationController | 1 | class ProjectsController < ApplicationController |
2 | + before_filter :authenticate_user!, | ||
3 | + except: [:index, :show] | ||
2 | 4 | ||
3 | # GET /projects/new | 5 | # GET /projects/new |
4 | def new | 6 | def new |
@@ -15,9 +17,10 @@ class ProjectsController < ApplicationController | @@ -15,9 +17,10 @@ class ProjectsController < ApplicationController | ||
15 | # POST /projects.json | 17 | # POST /projects.json |
16 | def create | 18 | def create |
17 | @project = Project.new(project_params) | 19 | @project = Project.new(project_params) |
18 | - | ||
19 | respond_to do |format| | 20 | respond_to do |format| |
20 | if @project.save | 21 | if @project.save |
22 | + current_user.project_ownerships.create project_id: @project.id | ||
23 | + | ||
21 | format.html { redirect_to project_path(@project.id), notice: 'Project was successfully created.' } | 24 | format.html { redirect_to project_path(@project.id), notice: 'Project was successfully created.' } |
22 | format.json { render action: 'show', status: :created, location: @project } | 25 | format.json { render action: 'show', status: :created, location: @project } |
23 | else | 26 | else |
@@ -32,7 +35,7 @@ class ProjectsController < ApplicationController | @@ -32,7 +35,7 @@ class ProjectsController < ApplicationController | ||
32 | def show | 35 | def show |
33 | set_project | 36 | set_project |
34 | end | 37 | end |
35 | - | 38 | + |
36 | # GET /projects/1/edit | 39 | # GET /projects/1/edit |
37 | # GET /projects/1/edit.json | 40 | # GET /projects/1/edit.json |
38 | def edit | 41 | def edit |
@@ -52,6 +55,7 @@ class ProjectsController < ApplicationController | @@ -52,6 +55,7 @@ class ProjectsController < ApplicationController | ||
52 | # DELETE /project/1.json | 55 | # DELETE /project/1.json |
53 | def destroy | 56 | def destroy |
54 | set_project | 57 | set_project |
58 | + current_user.project_ownerships.find_by_project_id(@project.id).destroy | ||
55 | @project.destroy | 59 | @project.destroy |
56 | respond_to do |format| | 60 | respond_to do |format| |
57 | format.html { redirect_to projects_url } | 61 | format.html { redirect_to projects_url } |
app/models/project_ownership.rb