Skip to content

Commit

Permalink
Merge pull request #38 from joelcogen/public-projects
Browse files Browse the repository at this point in the history
Allow some projects to be publicly visible
  • Loading branch information
Joel Cogen committed Sep 9, 2012
2 parents 307cd3d + 9dbbf70 commit 4ba8b9d
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/assets/stylesheets/application/base.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ body
form .checkbox-inner
padding: 0 0 0 95px
.col-box
width: 45%
width: 48%
float: left
margin: 0 10% 0 0
margin: 0 4% 0 0
select
width: 110px
.col-box2
width: 45%
width: 48%
float: left
select
width: 110px
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ class ApplicationController < ActionController::Base
before_filter :find_projects

def find_projects
@projects = current_user.try(:projects) || []
@projects = (Project.public + (current_user.try(:projects) || [])).uniq
end

def on_login_page?
%w(sessions registrations passwords).include? controller_name
end
helper_method :on_login_page?

rescue_from CanCan::AccessDenied do |exception|
if user_signed_in?
flash[:error] = exception.message
Expand Down
1 change: 1 addition & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class ProjectsController < ApplicationController
load_and_authorize_resource :except => :add_user_or_invite

def index
redirect_to(login_url) and return unless user_signed_in? || @projects.any?
respond_to do |format|
format.html
format.js { render partial: @projects }
Expand Down
2 changes: 2 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def initialize(user)
end
end
else
can :read, Project, public: true

can :create, User do |u|
!User.any?
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Project < ActiveRecord::Base

before_validation :create_hook_token, on: :create

scope :public, where(public: true)

def self.build_all_nightly!
Project.where(build_nightly: true).each do |project|
build = project.builds.create
Expand Down
14 changes: 12 additions & 2 deletions app/views/layouts/_header.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- if user_signed_in?
- unless on_login_page?
%header
%h1.small-logo
%a{:href =>"/", :title =>"Bennett - Go to dashboard"}
Expand All @@ -11,12 +11,22 @@
- if user_signed_in?
%li.logout
= link_to destroy_user_session_path, :method => :delete do
%span.hide-responsive Log Out
%span.hide-responsive Log out
%span.show-responsive
%i.icon-off.icon-white
- else
%li.logout
= link_to new_user_session_path do
%span.hide-responsive Login
%span.show-responsive
%i.icon-off.icon-white
.clear
- else
%header
- if @projects.any?
%ul.nav.nav-pills
%li.hide-responsive= link_to "Back to dashboard", projects_path
%li.show-responsive= link_to "Dashboard", projects_path
%h1.logo
%a{:href =>"/", :title =>"Bennett - Go to homepage"}
%span.hide Bennett
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
= javascript_include_tag :application
= csrf_meta_tags
%meta{:name => "viewport", :content => "width=device-width, initial-scale=1, maximum-scale=1"}
%body{:class => user_signed_in? ? 'connection-mode' : ''}
%body{:class => on_login_page? ? '' : 'connection-mode'}
.container
= render partial: 'layouts/header', locals: { projects: @projects, current_project: @project }
.content
Expand Down
6 changes: 6 additions & 0 deletions app/views/projects/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@
= form.label :build_nightly, :class => "checkbox-style1"
.clear
%span.help-block Build every night at 1:00 regardless of activity
- form.labeled_input :public do
.input.checkbox-btn
= form.check_box :public
= form.label :public, :class => "checkbox-style1"
.clear
%span.help-block Make this project publicly visible
.input
= form.submit "Save the project", :class => "btn"
5 changes: 4 additions & 1 deletion app/views/projects/_settings.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
%strong Recentizer&#153; 3000 Pro:
= @project.recentizer? ? 'On' : 'Off'
%p
%strong Build nightly:
%strong Nightly build:
= @project.build_nightly? ? 'On' : 'Off'
%p
%strong Visibility:
= @project.public? ? 'Public' : 'Private'
%p
%strong Post-Receive URL for Git hook:
= project_builds_url(@project, format: :json, t: @project.hook_token)
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20120717114259_add_public_to_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPublicToProjects < ActiveRecord::Migration
def change
add_column :projects, :public, :boolean, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120707154628) do
ActiveRecord::Schema.define(:version => 20120717114259) do

create_table "builds", :force => true do |t|
t.integer "project_id"
Expand Down Expand Up @@ -49,6 +49,7 @@
t.datetime "updated_at", :null => false
t.string "hook_token"
t.boolean "build_nightly", :default => false
t.boolean "public", :default => false
end

create_table "results", :force => true do |t|
Expand Down

0 comments on commit 4ba8b9d

Please sign in to comment.