• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sleede / fab-manager / #106

pending completion
#106

push

coveralls-ruby

sylvainbx
Merge branch 'dev' for release 6.0.0

704 of 704 new or added lines in 168 files covered. (100.0%)

7919 of 13474 relevant lines covered (58.77%)

15.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/controllers/api/projects_controller.rb
1
# frozen_string_literal: true
2

3
# API Controller for resources of type Project
4
class API::ProjectsController < API::APIController
×
5
  before_action :authenticate_user!, except: %i[index show last_published search]
×
6
  before_action :set_project, only: %i[update destroy]
×
7
  respond_to :json
×
8

9
  def index
×
10
    @projects = policy_scope(Project).page(params[:page])
×
11
  end
×
12

13
  def last_published
×
14
    @projects = Project.includes(:project_image).published.order('created_at desc').limit(5)
×
15
  end
×
16

17
  def show
×
18
    @project = Project.friendly.find(params[:id])
×
19
  end
×
20

21
  def create
×
22
    @project = Project.new(project_params.merge(author_statistic_profile_id: current_user.statistic_profile.id))
×
23
    if @project.save
×
24
      render :show, status: :created, location: @project
×
25
    else
×
26
      render json: @project.errors, status: :unprocessable_entity
×
27
    end
×
28
  end
×
29

30
  def update
×
31
    authorize @project
×
32
    if @project.update(project_params)
×
33
      render :show, status: :ok, location: @project
×
34
    else
×
35
      render json: @project.errors, status: :unprocessable_entity
×
36
    end
×
37
  end
×
38

39
  def destroy
×
40
    authorize @project
×
41
    @project.destroy
×
42
    head :no_content
×
43
  end
×
44

45
  def collaborator_valid
×
46
    project_user = ProjectUser.find_by(valid_token: params[:valid_token])
×
47
    if project_user
×
48
      project_user.update(is_valid: true, valid_token: '')
×
49
      redirect_to "/#!/projects/#{project_user.project.id}" and return
×
50
    end
×
51
    redirect_to root_url
×
52
  end
×
53

54
  def search
×
55
    service = ProjectService.new
×
56
    res = service.search(params, current_user)
×
57
    render json: res, status: :unprocessable_entity and return if res[:error]
×
58

59
    @total = res[:total]
×
60
    @projects = res[:projects]
×
61
    render :index
×
62
  end
×
63

64
  private
×
65

66
  def set_project
×
67
    @project = Project.find(params[:id])
×
68
  end
×
69

70
  def project_params
×
71
    params.require(:project).permit(:name, :description, :tags, :machine_ids, :component_ids, :theme_ids, :licence_id, :status_id, :state,
×
72
                                    user_ids: [], machine_ids: [], component_ids: [], theme_ids: [],
×
73
                                    project_image_attributes: [:attachment],
×
74
                                    project_caos_attributes: %i[id attachment _destroy],
×
75
                                    project_steps_attributes: [
×
76
                                      :id, :description, :title, :_destroy, :step_nb,
×
77
                                      { project_step_images_attributes: %i[id attachment _destroy] }
×
78
                                    ])
×
79
  end
×
80
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc