Permalink
Browse files

Added external ids to Issues

  • Loading branch information...
1 parent f0837c5 commit 9b108a0ad7427ecd05446d2278f5ab25bfdb21ef @christydennison committed Apr 23, 2012
@@ -3,15 +3,19 @@ class IssuesController < ApplicationController
:only => [:index, :new, :create]
def current_user_can_read_issue
- @issue = Issue.find(params[:id])
+ @profile = Profile.where(:name => params[:profile_name]).first
+ @repository = @profile.repositories.where(:name => params[:repo_name]).first
+ @issue = @repository.issues.where(:exid => params[:issue_exid]).first
bounce_user unless @issue.can_read? current_user
end
private :current_user_can_read_issue
before_filter :current_user_can_read_issue,
:only => [:show]
def current_user_can_edit_issue
- @issue = Issue.find(params[:id])
+ @profile = Profile.where(:name => params[:profile_name]).first
+ @repository = @profile.repositories.where(:name => params[:repo_name]).first
+ @issue = @repository.issues.where(:exid => params[:issue_exid]).first
bounce_user unless @issue.can_edit? current_user
end
private :current_user_can_edit_issue
@@ -34,7 +38,9 @@ def index
# GET /costan/rails/issues/1
# GET /costan/rails/issues/1.xml
def show
- @issue = Issue.find(params[:id])
+ @profile = Profile.where(:name => params[:profile_name]).first
+ @repository = @profile.repositories.where(:name => params[:repo_name]).first
+ @issue = @repository.issues.where(:exid => params[:issue_exid]).first
respond_to do |format|
format.html # show.html.erb
@@ -59,8 +65,9 @@ def new
# GET /costan/rails/issues/1/edit
def edit
- @issue = Issue.find(params[:id])
- @repository = @issue.repository
+ @profile = Profile.where(:name => params[:profile_name]).first
+ @repository = @profile.repositories.where(:name => params[:repo_name]).first
+ @issue = @repository.issues.where(:exid => params[:issue_exid]).first
respond_to do |format|
format.html # edit.html.erb
@@ -78,12 +85,11 @@ def create
@issue = Issue.new params[:issue]
@issue.repository = @repository
@issue.author = @author
-
+
respond_to do |format|
if @issue.save
@issue.publish_opening
FeedSubscription.add @author, @issue
-
format.html do
redirect_to profile_repository_issues_path(@profile, @repository),
notice: 'Issue was successfully created.'
@@ -103,7 +109,9 @@ def create
# PUT /costan/rails/issues/1
# PUT /costan/rails/issues/1.xml
def update
- @issue = Issue.find(params[:id])
+ @profile = Profile.where(:name => params[:profile_name]).first
+ @repository = @profile.repositories.where(:name => params[:repo_name]).first
+ @issue = @repository.issues.where(:exid => params[:issue_exid]).first
respond_to do |format|
if @issue.update_attributes(params[:issue])
@@ -135,7 +143,10 @@ def update
# DELETE /costan/rails/issues/1
# DELETE /costan/rails/issues/1.xml
def destroy
- @issue = Issue.find(params[:id])
+ @profile = Profile.where(:name => params[:profile_name]).first
+ @repository = @profile.repositories.where(:name => params[:repo_name]).first
+ @issue = @repository.issues.where(:exid => params[:issue_exid]).first
+
FeedSubscription.remove @issue.author, @issue
FeedItem.delete(FeedItem.where(:author_id => @issue.author,
:target_type => "Issue",
@@ -16,4 +16,9 @@ def readable_open_issues(issues, user)
def readable_closed_issues(issues, user)
issues.select { |i| i.can_read?(user) && !i.open? }
end
+
+ # Returns number of readable open issues
+ def readable_open_issues_counter(issues, user)
+ issues.select { |i| i.can_read?(user) && i.open? }.length
+ end
end
View
@@ -21,6 +21,35 @@ class Issue < ActiveRecord::Base
# True for issues that have sensitive information and so will only be seen by
# the developers and the author.
validates :sensitive, :inclusion => { :in => [true, false] }
+
+ # Externally-visible issue ID.
+ #
+ # This is decoupled from "id" column to avoid leaking information about
+ # the application's usage.
+ validates :exid, :presence => true,
+ :numericality => { :greater_than => 0 },
+ :uniqueness => { :scope => :repository_id }
+
+ # Automatically set the exid
+ before_validation :set_default_exid, :on => :create
+
+ # Use external IDs for routes instead of IDs.
+ def to_param
+ exid.to_s
+ end
+
+ # Returns next valid external id for an issue
+ def self.next_exid(repo)
+ if repo && (repo.issues.length > 0)
+ return repo.issues.order('exid').last.exid + 1
+ end
+ 1 # first issue in sequence
+ end
+
+ # Set the exid of the issue
+ def set_default_exid
+ self.exid ||= Issue.next_exid(self.repository)
+ end
end
# :nodoc: access control
@@ -10,7 +10,7 @@
<%= render issues %>
<% end %>
- <% unless (_issues = readable_closed_issues(@issues, current_user)).empty? %>
+ <% unless (issues = readable_closed_issues(@issues, current_user)).empty? %>
<h2>Closed Issues</h2>
<%= render issues %>
<% end %>
@@ -83,8 +83,9 @@
repository) %>
</li>
<li>
- <%= link_to 'Issues', profile_repository_issues_path(repository.profile,
- repository) %>
+ <%= link_to "Issues (#{readable_open_issues_counter(repository.issues,
+ current_user)})",
+ profile_repository_issues_path(repository.profile, repository) %>
</li>
<% if repository.can_edit? current_user %>
<li>
View
@@ -115,11 +115,11 @@
resources :issues, :only => [:create]
get 'issues' => 'issues#index', :as => :profile_repository_issues
get 'issues/new' => 'issues#new', :as => :new_profile_repository_issue
- get 'issues/:id' => 'issues#show', :as => :profile_repository_issue
- get 'issues/:id/edit(.:format)' => 'issues#edit',
+ get 'issues/:issue_exid' => 'issues#show', :as => :profile_repository_issue
+ get 'issues/:issue_exid/edit(.:format)' => 'issues#edit',
:as => :edit_profile_repository_issue
- put 'issues/:id' => 'issues#update'
- delete 'issues/:id' => 'issues#destroy'
+ put 'issues/:issue_exid' => 'issues#update'
+ delete 'issues/:issue_exid' => 'issues#destroy'
# Admin.
get 'edit' => 'repositories#edit', :as => :edit_profile_repository
@@ -5,13 +5,16 @@ def change
t.references :author, :null => false
t.boolean :open, :default => true, :null => false
t.boolean :sensitive, :default => false, :null => false
- t.string :title, :length => 160, :null => false
- t.text :description, :length => 1.kilobyte, :null => false
+ t.string :title, :limit => 160, :null => false
+ t.text :description, :limit => 1.kilobyte, :null => false
+ t.integer :exid, :limit => 1..32, :null => false
t.timestamps
end
add_index :issues, [:author_id, :open], :unique => false, :null => false
add_index :issues, [:repository_id, :open], :unique => false, :null => false
+ add_index :issues, [:repository_id, :exid], :unique => true,
+ :null => false
end
end
View
@@ -27,10 +27,10 @@
add_index "acl_entries", ["subject_id", "subject_type", "principal_id", "principal_type"], :name => "index_acl_entries_by_subject_principal", :unique => true
create_table "blobs", :force => true do |t|
- t.integer "repository_id", :null => false
- t.string "gitid", :limit => 64, :null => false
- t.string "mime_type", :limit => 64, :null => false
- t.integer "size", :null => false
+ t.integer "repository_id", :null => false
+ t.integer "size", :null => false
+ t.string "gitid", :limit => 64, :null => false
+ t.string "mime_type", :limit => 256, :null => false
end
add_index "blobs", ["repository_id", "gitid"], :name => "index_blobs_on_repository_id_and_gitid", :unique => true
@@ -139,17 +139,19 @@
add_index "feed_subscriptions", ["topic_id", "topic_type", "profile_id"], :name => "index_feed_subscriptions_on_topic_profile", :unique => true
create_table "issues", :force => true do |t|
- t.integer "repository_id", :null => false
- t.integer "author_id", :null => false
- t.boolean "open", :default => true, :null => false
- t.boolean "sensitive", :default => false, :null => false
- t.string "title", :null => false
- t.text "description", :null => false
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.integer "repository_id", :null => false
+ t.integer "author_id", :null => false
+ t.boolean "open", :default => true, :null => false
+ t.boolean "sensitive", :default => false, :null => false
+ t.string "title", :limit => 160, :null => false
+ t.text "description", :null => false
+ t.integer "exid", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
end
add_index "issues", ["author_id", "open"], :name => "index_issues_on_author_id_and_open"
+ add_index "issues", ["repository_id", "exid"], :name => "index_issues_on_repository_id_and_exid", :unique => true
add_index "issues", ["repository_id", "open"], :name => "index_issues_on_repository_id_and_open"
create_table "profiles", :force => true do |t|
@@ -3,6 +3,7 @@ costan_ghost_translated:
repository: costan_ghost
open: true
sensitive: false
+ exid: 42
title: Missing translation
description: The text files in this project are English-only. It would be nice
if they had translations.
@@ -12,6 +13,7 @@ public_ghost_dead_code:
repository: public_ghost
open: true
sensitive: false
+ exid: 1
title: Dead code
description: There's a bunch of dead code in the controller files.
@@ -20,6 +22,7 @@ public_ghost_security_vulnerability:
repository: public_ghost
open: true
sensitive: true
+ exid: 2
title: Security Vulnerability
description: There's a huge chance someone could break the app in line 10.
@@ -28,6 +31,7 @@ public_ghost_pizza:
repository: public_ghost
open: true
sensitive: true
+ exid: 3
title: Meta-x Pizza
description: I keep on trying to hit 'm-x pizza', but no pizza jumps out of
the screen. Help?
@@ -37,6 +41,7 @@ public_ghost_jquery:
repository: public_ghost
open: false
sensitive: false
+ exid: 4
title: Needs more jQuery
description: The lack of jQuery in this repo is too high!
@@ -45,6 +50,7 @@ public_ghost_code_language:
repository: public_ghost
open: false
sensitive: true
+ exid: 7
title: Code language request
description: I think the code should be rewritten in a more popular language,
like LOLCODE. You'll be able to reach a far wider audience with it.
Oops, something went wrong.

0 comments on commit 9b108a0

Please sign in to comment.