Skip to content
Snippets Groups Projects
Commit 30bd6637 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Implement minimal public access

parent e8270c1e
No related branches found
No related tags found
No related merge requests found
require 'runner'
 
class ProjectsController < ApplicationController
before_filter :authenticate_user!, except: [:build, :status]
before_filter :authenticate_user!, except: [:build, :status, :index, :show]
before_filter :project, only: [:build, :details, :show, :status, :edit, :update, :destroy, :stats]
before_filter :authenticate_token!, only: [:build]
 
def index
@projects = Project.order('id DESC').paginate(page: params[:page], per_page: 20)
@projects = Project.order('id DESC')
@projects = @projects.public unless current_user
@projects = @projects.paginate(page: params[:page], per_page: 20)
end
 
def show
unless @project.public || current_user
authenticate_user! and return
end
@ref = params[:ref]
 
@builds = @project.builds
@builds = @builds.where(ref: @ref) if @ref
@builds = @builds.latest_sha.order('id DESC').paginate(page: params[:page], per_page: 20)
Loading
Loading
class Project < ActiveRecord::Base
attr_accessible :name, :path, :scripts, :timeout, :token,
:default_ref, :gitlab_url, :always_build, :polling_interval
:default_ref, :gitlab_url, :always_build, :polling_interval, :public
 
has_many :builds, dependent: :destroy
 
Loading
Loading
@@ -16,6 +16,9 @@ class Project < ActiveRecord::Base
presence: true,
if: ->(project) { project.always_build.present? }
 
scope :public, where(public: true)
before_validation :set_default_values
 
def set_default_values
Loading
Loading
@@ -146,3 +149,23 @@ end
# token :string(255)
# default_ref :string(255)
#
# == Schema Information
#
# Table name: projects
#
# id :integer(4) not null, primary key
# name :string(255) not null
# path :string(255) not null
# timeout :integer(4) default(1800), not null
# scripts :text default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# token :string(255)
# default_ref :string(255)
# gitlab_url :string(255)
# always_build :boolean(1) default(FALSE), not null
# polling_interval :integer(4)
# public :boolean(1) default(FALSE), not null
#
Loading
Loading
@@ -17,6 +17,10 @@
.field
= f.label :token, "Token (Leave empty to generate random token)"
= f.text_field :token, class: 'input-xlarge', placeholder: 'xEeFCaDAB89'
.field
= f.label :public do
= f.check_box :public, class: 'input-xlarge'
%span Public (Anyone can see project and builds list)
 
%fieldset
%legend Git
Loading
Loading
Loading
Loading
@@ -19,6 +19,10 @@
%i.icon-edit.icon-white
Edit
 
- if project.public
%span.pull-right
%i.icon-globe
Public
.clearfix
= will_paginate @projects
- if @projects.empty?
Loading
Loading
%h3
Project: #{@project.name}
- if @project.public
%small (Public)
- if @project.gitlab_url.present?
%small= link_to 'View on GitLab', @project.gitlab_url
.pull-right
%span
= link_to details_project_path(@project), class: 'btn btn-small' do
Details
%span
= link_to stats_project_path(@project), class: 'btn btn-small' do
Stats
%span
= link_to edit_project_path(@project), class: 'btn btn-small' do
%i.icon-edit.icon-white
Edit
- if current_user
.pull-right
%span
= link_to details_project_path(@project), class: 'btn btn-small' do
Details
%span
= link_to stats_project_path(@project), class: 'btn btn-small' do
Stats
%span
= link_to edit_project_path(@project), class: 'btn btn-small' do
%i.icon-edit.icon-white
Edit
 
 
%ul.nav.nav-tabs
Loading
Loading
@@ -27,11 +32,12 @@
%p
Paste build status image for #{@ref} with next link
%a.btn.btn-small{href: status_project_path(@project, ref: @ref)} Status Badge
%p
You can manually run a build for current branch.
= link_to run_project_path(@project, ref: @ref), class: 'btn btn-small' do
%i.icon-play.icon-white
Run a build
- if current_user
%p
You can manually run a build for current branch.
= link_to run_project_path(@project, ref: @ref), class: 'btn btn-small' do
%i.icon-play.icon-white
Run a build
 
%table.builds
%thead
Loading
Loading
class AddPublicFlagToProject < ActiveRecord::Migration
def change
add_column :projects, :public, :boolean, null: false, default: false
end
end
Loading
Loading
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
 
ActiveRecord::Schema.define(:version => 20130114153451) do
ActiveRecord::Schema.define(:version => 20130129121754) do
 
create_table "builds", :force => true do |t|
t.integer "project_id"
Loading
Loading
@@ -39,6 +39,7 @@ ActiveRecord::Schema.define(:version => 20130114153451) do
t.string "gitlab_url"
t.boolean "always_build", :default => false, :null => false
t.integer "polling_interval"
t.boolean "public", :default => false, :null => false
end
 
create_table "users", :force => true do |t|
Loading
Loading
Loading
Loading
@@ -57,17 +57,21 @@ end
#
# Table name: projects
#
# id :integer(4) not null, primary key
# name :string(255) not null
# path :string(255) not null
# timeout :integer(4) default(1800), not null
# scripts :text default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# token :string(255)
# default_ref :string(255)
# id :integer(4) not null, primary key
# name :string(255) not null
# path :string(255) not null
# timeout :integer(4) default(1800), not null
# scripts :text default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# token :string(255)
# default_ref :string(255)
# gitlab_url :string(255)
# always_build :boolean(1) default(FALSE), not null
# polling_interval :integer(4)
#
 
# == Schema Information
#
# Table name: projects
Loading
Loading
@@ -84,5 +88,6 @@ end
# gitlab_url :string(255)
# always_build :boolean(1) default(FALSE), not null
# polling_interval :integer(4)
# public :boolean(1) default(FALSE), not null
#
 
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment