Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Anonymous users have access to read only projects #49

Closed
wants to merge 6 commits into from

3 participants

@wasabhi

First couple of steps as requested are complete. I need some assistance to tackle the JS UI read only side of things, lets chat offline to discuss and I will send another pull request.

@malclocke
Owner

Just need a checkbox on the projects#edit form so set the public flag. Will also need access to the ChangesetsController on public projects.

Stuff that needs to be done for contextual JS UI:

  • Some method in JS like Project.isReadOnly() or similar.
  • Hide the projects drop down top right.
  • Hide 'stories | members | edit ... ' links
  • Don't initialize the dragable behaviours (public/javascripts/fulcrum.js)
  • Hide the 'expand form' button on each story.
  • Replace the 'Estimate', 'Start', 'Finish', 'Deliver', etc. buttons with an indicator of the stories current state.

That's all I can think of atm.

@wasabhi

Cool, expect more soon.

@malclocke
Owner

Probably easiest wrt to the story display to set up a new jQuery.tmpl rather than filling the existing one up with if statements. The existing one is embedded in app/views/projects/show.html.erb

@parndt

Is this likely to be a goer?

@malclocke
Owner

Closing this as it's probably not going to rebase any more. Thank you for the work @wasabhi, will probably use it as reference when this eventually gets implemented. Sorry we didn't get around to getting it over the line :(

@malclocke malclocke closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -4,4 +4,5 @@ db/*.sqlite3
log/*.log
tmp/**/*
.rvmrc
+*.swp
public/stylesheets/*
View
12 app/controllers/application_controller.rb
@@ -22,4 +22,16 @@ def render_404
end
end
end
+
+ private
+ def permit_public_project
+ project_id = params[:id] ? params[:id] : params[:project_id]
+ project = Project.find(project_id)
+ unless project.public?
+ authenticate_user!
+ @project = current_user.projects.find(project_id)
+ else
+ @project = project
+ end
+ end
end
View
4 app/controllers/changesets_controller.rb
@@ -1,6 +1,8 @@
class ChangesetsController < ApplicationController
+ skip_before_filter :authenticate_user!, :only => [:index]
+ before_filter :permit_public_project, :only => [:index]
+
def index
- @project = current_user.projects.find(params[:project_id])
scope = @project.changesets.scoped
scope = scope.where('id <= ?', params[:to]) if params[:to]
scope = scope.where('id > ?', params[:from]) if params[:from]
View
3  app/controllers/projects_controller.rb
@@ -1,4 +1,6 @@
class ProjectsController < ApplicationController
+ skip_before_filter :authenticate_user!, :only => [:show]
+ before_filter :permit_public_project, :only => [:show]
# GET /projects
# GET /projects.xml
@@ -13,7 +15,6 @@ def index
# GET /projects/1
# GET /projects/1.xml
def show
- @project = current_user.projects.find(params[:id])
@story = @project.stories.build
respond_to do |format|
View
4 app/controllers/stories_controller.rb
@@ -1,9 +1,10 @@
class StoriesController < ApplicationController
+ skip_before_filter :authenticate_user!, :only => [:index, :show]
+ before_filter :permit_public_project, :only => [:index, :show]
include ActionView::Helpers::TextHelper
def index
- @project = current_user.projects.find(params[:project_id])
@stories = @project.stories
respond_to do |format|
format.json { render :json => @stories }
@@ -14,7 +15,6 @@ def index
end
def show
- @project = current_user.projects.find(params[:project_id])
@story = @project.stories.find(params[:id])
render :json => @story
end
View
4 app/stylesheets/screen.scss
@@ -461,3 +461,7 @@ a.button:hover {
padding:10px 15px 0px;
}
}
+
+.clearfix {
+ clear: both;
+}
View
4 app/views/projects/_form.html.erb
@@ -33,6 +33,10 @@
<%= f.label :iteration_length %><br />
<%= f.select :iteration_length, iteration_length_options %>
</div>
+ <div class="field">
+ <%= f.label :public %><br />
+ <%= f.check_box :public %>
+ </div>
<div class="actions">
<%= f.submit %>
</div>
View
15 app/views/projects/_nav.html.erb
@@ -9,8 +9,13 @@
</div>
<%- end -%>
-<%= link_to_unless_current 'Stories', project_path(project) %> |
-<%= link_to_unless_current 'Members', project_users_path(project) %> |
-<%= link_to_unless_current 'Edit', edit_project_path(project) %> |
-<%= link_to_unless_current 'Import', import_project_stories_path(project) %> |
-<%= link_to 'Export', project_stories_path(project, :format => :csv) %>
+<% unless current_user.nil? && project.public? %>
+ <%= link_to_unless_current 'Stories', project_path(project) %> |
+ <%= link_to_unless_current 'Members', project_users_path(project) %> |
+ <%= link_to_unless_current 'Edit', edit_project_path(project) %> |
+ <%= link_to_unless_current 'Import', import_project_stories_path(project) %> |
+ <%= link_to 'Export', project_stories_path(project, :format => :csv) %> |
+ <a id="add_story" href="#">Add story</a>
+<% end %>
+
+<div class="clearfix"></div>
View
1  app/views/projects/show.html.erb
@@ -87,7 +87,6 @@ $(function() {
<% content_for :title_bar do %>
<%= render :partial => 'projects/nav',
:locals => {:project => @project, :show_column_toggles => true} %>
- | <a id="add_story" href="#">Add story</a>
<% end %>
<table class="stories" width="100%">
View
9 db/migrate/20111002092354_add_public_to_projects.rb
@@ -0,0 +1,9 @@
+class AddPublicToProjects < ActiveRecord::Migration
+ def self.up
+ add_column :projects, :public, :boolean, :default => false
+ end
+
+ def self.down
+ remove_column :projects, :public
+ end
+end
View
3  db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110914211417) do
+ActiveRecord::Schema.define(:version => 20111002092354) do
create_table "changesets", :force => true do |t|
t.integer "story_id"
@@ -27,6 +27,7 @@
t.integer "iteration_length", :default => 1
t.datetime "created_at"
t.datetime "updated_at"
+ t.boolean "public", :default => false
end
create_table "projects_users", :id => false, :force => true do |t|
View
17 test/functional/changesets_controller_test.rb
@@ -24,4 +24,21 @@ class ChangesetsControllerTest < ActionController::TestCase
assert_response :success
assert_equal [@changeset], assigns(:changesets)
end
+
+ test "should get all for anonymous users in json format for public projects" do
+ @project.public = true
+ @project.save
+ get :index, :project_id => @project.to_param, :format => 'json'
+ assert_response :success
+ assert_equal @project.changesets, assigns(:changesets)
+ end
+
+ test "should get for anonymous users in json format with from and to params for public projects" do
+ @project.public = true
+ @project.save
+ get :index, :project_id => @project.to_param, :format => 'json',
+ :from => @changeset.id - 1, :to => @changeset.id
+ assert_response :success
+ assert_equal [@changeset], assigns(:changesets)
+ end
end
View
17 test/functional/projects_controller_test.rb
@@ -61,6 +61,23 @@ class ProjectsControllerTest < ActionController::TestCase
assert_response :missing
end
+ test "should anonymously show public project" do
+ @project.public = true
+ @project.save
+ get :show, :id => @project.to_param
+ assert_equal @project, assigns(:project)
+ assert assigns(:story)
+ assert_response :success
+ end
+
+ test "should anonymously show public project in js format" do
+ @project.public = true
+ @project.save
+ get :show, :id => @project.to_param, :format => 'js'
+ assert_equal @project, assigns(:project)
+ assert_response :success
+ end
+
test "should get edit" do
sign_in @user
get :edit, :id => @project.to_param
View
17 test/functional/stories_controller_test.rb
@@ -77,6 +77,23 @@ def setup
assert_equal @project, assigns(:project)
assert_equal @project.stories, assigns(:stories)
end
+
+ test "should get a single story in a public project for an anonymous user in js format" do
+ @project.public = true
+ @project.save
+ get :show, :project_id => @project.to_param, :id => @story.to_param,
+ :format => 'js'
+ assert_equal @project, assigns(:project)
+ assert_equal @story, assigns(:story)
+ end
+
+ test "should get all stories in a public project for an anonymous user in js format" do
+ @project.public = true
+ @project.save
+ get :index, :project_id => @project.to_param, :format => 'js'
+ assert_equal @project, assigns(:project)
+ assert_equal @project.stories, assigns(:stories)
+ end
test "should get done stories in js format" do
sign_in @user
get :done, :project_id => @project.to_param, :format => 'js'
View
4 test/unit/project_test.rb
@@ -19,6 +19,10 @@ def setup
assert_equal 'fibonacci', Project.new.point_scale
end
+ test "default public flag should be false" do
+ assert_equal false, @project.public
+ end
+
test "should reject invalid point scale" do
@project.point_scale = 'invalid_point_scale'
assert !@project.save
Something went wrong with that request. Please try again.