#34: added Hook model, controller, views
This commit is contained in:
parent
28fe61330a
commit
d28a2b0173
|
@ -0,0 +1,87 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Projects::HooksController < Projects::BaseController
|
||||
before_filter :authenticate_user!
|
||||
load_resource :project
|
||||
|
||||
# GET /../hooks
|
||||
# GET /../hooks.json
|
||||
def index
|
||||
@hooks = @project.hooks.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @hooks }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /../hooks/1
|
||||
# GET /../hooks/1.json
|
||||
def show
|
||||
@hook = @project.hooks.find params[:id]
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @hook }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /../hooks/new
|
||||
# GET /../hooks/new.json
|
||||
def new
|
||||
@hook = @project.hooks.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @hook }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /../hooks/1/edit
|
||||
def edit
|
||||
@hook = @project.hooks.find params[:id]
|
||||
end
|
||||
|
||||
# POST /../hooks
|
||||
# POST /../hooks.json
|
||||
def create
|
||||
@hook = @project.hooks.new params[:hook]
|
||||
|
||||
respond_to do |format|
|
||||
if @hook.save
|
||||
format.html { redirect_to @hook, notice: 'Hook was successfully created.' }
|
||||
format.json { render json: @hook, status: :created, location: @hook }
|
||||
else
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: @hook.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /../hooks/1
|
||||
# PUT /../hooks/1.json
|
||||
def update
|
||||
@hook = @project.hooks.find params[:id]
|
||||
|
||||
respond_to do |format|
|
||||
if @hook.update_attributes(params[:hook])
|
||||
format.html { redirect_to @hook, notice: 'Hook was successfully updated.' }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: @hook.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /../hooks/1
|
||||
# DELETE /../hooks/1.json
|
||||
def destroy
|
||||
@hook = @project.hooks.find params[:id]
|
||||
@hook.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to hooks_url }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module HooksHelper
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
class Hook < ActiveRecord::Base
|
||||
TYPES = [1, 2]
|
||||
|
||||
belongs_to :project
|
||||
|
||||
validates :project_id, :presence => true
|
||||
validates :data, :presence => true
|
||||
validates :type, :presence => true, :inclusion => {:in => TYPES}
|
||||
validates :type, :uniqueness => {:scope => :project_id}
|
||||
|
||||
attr_accessible :data, :type
|
||||
|
||||
serialize :data, Hash
|
||||
end
|
|
@ -17,6 +17,7 @@ class Project < ActiveRecord::Base
|
|||
has_many :project_tags, :dependent => :destroy
|
||||
|
||||
has_many :build_lists, :dependent => :destroy
|
||||
has_many :hooks, :dependent => :destroy
|
||||
|
||||
has_many :relations, :as => :target, :dependent => :destroy
|
||||
has_many :collaborators, :through => :relations, :source => :actor, :source_type => 'User'
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
= link_to t("layout.projects.edit"), edit_project_path(@project)
|
||||
%li{:class => (act == :sections && contr == :projects) ? 'active' : ''}
|
||||
= link_to t("layout.projects.sections"), sections_project_path(@project)
|
||||
%li{:class => (contr == :hooks) ? 'active' : ''}
|
||||
= link_to t("layout.projects.hooks"), project_hooks_path(@project)
|
||||
- if can? :manage_collaborators, @project
|
||||
%li{:class => (act == :index && contr == :collaborators) ? 'active' : ''}
|
||||
= link_to t("layout.projects.edit_collaborators"), project_collaborators_path(@project)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
= form_for [@project, @hook] do |f|
|
||||
- if @hook.errors.any?
|
||||
#error_explanation
|
||||
%h2= "#{pluralize(@hook.errors.count, "error")} prohibited this hook from being saved:"
|
||||
%ul
|
||||
- @hook.errors.full_messages.each do |msg|
|
||||
%li= msg
|
||||
|
||||
.field
|
||||
= f.label :type
|
||||
= f.select :type, Hook::TYPES
|
||||
.field
|
||||
= f.label :data
|
||||
= f.text_area :data
|
||||
.actions
|
||||
= f.submit 'Save'
|
|
@ -0,0 +1,11 @@
|
|||
-set_meta_tags :title => [title_object(@project), t('layout.projects.hooks')]
|
||||
= render 'submenu'
|
||||
= render 'sidebar'
|
||||
|
||||
%h1 Editing hook
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Show', @hook
|
||||
\|
|
||||
= link_to 'Back', project_hooks_path(@project)
|
|
@ -0,0 +1,25 @@
|
|||
-set_meta_tags :title => [title_object(@project), t('layout.projects.hooks')]
|
||||
= render 'submenu'
|
||||
= render 'sidebar'
|
||||
|
||||
%h1 Listing hooks
|
||||
|
||||
%table
|
||||
%tr
|
||||
%th Data
|
||||
%th Type
|
||||
%th
|
||||
%th
|
||||
%th
|
||||
|
||||
- @hooks.each do |hook|
|
||||
%tr
|
||||
%td= hook.data
|
||||
%td= hook.type
|
||||
%td= link_to 'Show', hook
|
||||
%td= link_to 'Edit', edit_project_hook_path(hook)
|
||||
%td= link_to 'Destroy', hook, method: :delete, data: { confirm: 'Are you sure?' }
|
||||
|
||||
%br
|
||||
|
||||
= link_to 'New Hook', new_project_hook_path(@project)
|
|
@ -0,0 +1,9 @@
|
|||
-set_meta_tags :title => [title_object(@project), t('layout.projects.hooks')]
|
||||
= render 'submenu'
|
||||
= render 'sidebar'
|
||||
|
||||
%h1 New hook
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Back', project_hooks_path(@project)
|
|
@ -0,0 +1,19 @@
|
|||
-set_meta_tags :title => [title_object(@project), t('layout.projects.hooks')]
|
||||
= render 'submenu'
|
||||
= render 'sidebar'
|
||||
|
||||
%p#notice= notice
|
||||
|
||||
%p
|
||||
%b Data:
|
||||
= @hook.data
|
||||
%p
|
||||
%b Project:
|
||||
= @hook.project_id
|
||||
%p
|
||||
%b Type:
|
||||
= @hook.type
|
||||
|
||||
= link_to 'Edit', edit_project_hook_path(@hook)
|
||||
\|
|
||||
= link_to 'Back', project_hooks_path
|
|
@ -278,6 +278,7 @@ Rosa::Application.routes.draw do
|
|||
resources :collaborators do
|
||||
get :find, :on => :collection
|
||||
end
|
||||
resources :hooks
|
||||
resources :pull_requests, :except => :destroy do
|
||||
get :autocomplete_to_project, :on => :collection
|
||||
put :merge, :on => :member
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class CreateHooks < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :hooks do |t|
|
||||
t.text :data
|
||||
t.integer :project_id
|
||||
t.integer :type
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
114
db/schema.rb
114
db/schema.rb
|
@ -11,14 +11,14 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130328112110) do
|
||||
ActiveRecord::Schema.define(:version => 20130412124536) do
|
||||
|
||||
create_table "activity_feeds", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
t.string "kind"
|
||||
t.text "data"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "advisories", :force => true do |t|
|
||||
|
@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
|
||||
create_table "arches", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true
|
||||
|
@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.integer "user_id"
|
||||
t.string "provider"
|
||||
t.string "uid"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true
|
||||
|
@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.integer "level"
|
||||
t.integer "status"
|
||||
t.integer "build_list_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "version"
|
||||
end
|
||||
|
||||
|
@ -110,8 +110,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.integer "project_id"
|
||||
t.integer "arch_id"
|
||||
t.datetime "notified_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "is_circle", :default => false
|
||||
t.text "additional_repos"
|
||||
t.string "name"
|
||||
|
@ -150,8 +150,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.string "commentable_type"
|
||||
t.integer "user_id"
|
||||
t.text "body"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.decimal "commentable_id", :precision => 50, :scale => 0
|
||||
t.integer "project_id"
|
||||
t.text "data"
|
||||
|
@ -178,8 +178,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.string "controller"
|
||||
t.string "action"
|
||||
t.text "message"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "flash_notifies", :force => true do |t|
|
||||
|
@ -193,8 +193,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
|
||||
create_table "groups", :force => true do |t|
|
||||
t.integer "owner_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "uname"
|
||||
t.integer "own_projects_count", :default => 0, :null => false
|
||||
t.text "description"
|
||||
|
@ -204,6 +204,14 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.datetime "avatar_updated_at"
|
||||
end
|
||||
|
||||
create_table "hooks", :force => true do |t|
|
||||
t.text "data"
|
||||
t.integer "project_id"
|
||||
t.integer "type"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "issues", :force => true do |t|
|
||||
t.integer "serial_id"
|
||||
t.integer "project_id"
|
||||
|
@ -211,8 +219,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.string "title"
|
||||
t.text "body"
|
||||
t.string "status", :default => "open"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "user_id"
|
||||
t.datetime "closed_at"
|
||||
t.integer "closed_by"
|
||||
|
@ -289,14 +297,14 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.string "description"
|
||||
t.string "name", :null => false
|
||||
t.integer "parent_platform_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "released", :default => false, :null => false
|
||||
t.integer "owner_id"
|
||||
t.string "owner_type"
|
||||
t.string "visibility", :default => "open", :null => false
|
||||
t.string "platform_type", :default => "main", :null => false
|
||||
t.string "distrib_type"
|
||||
t.string "distrib_type", :null => false
|
||||
end
|
||||
|
||||
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false
|
||||
|
@ -305,16 +313,16 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.integer "platform_id"
|
||||
t.string "login"
|
||||
t.string "password"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "user_id"
|
||||
end
|
||||
|
||||
create_table "product_build_lists", :force => true do |t|
|
||||
t.integer "product_id"
|
||||
t.integer "status", :default => 3, :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "status", :default => 2, :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "project_id"
|
||||
t.string "project_version"
|
||||
t.string "commit_hash"
|
||||
|
@ -333,8 +341,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
create_table "products", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.integer "platform_id", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.text "description"
|
||||
t.integer "project_id"
|
||||
t.string "params"
|
||||
|
@ -349,8 +357,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.string "name"
|
||||
t.string "version"
|
||||
t.datetime "file_mtime"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "platform_id"
|
||||
end
|
||||
|
||||
|
@ -369,27 +377,27 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
create_table "project_to_repositories", :force => true do |t|
|
||||
t.integer "project_id"
|
||||
t.integer "repository_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "project_to_repositories", ["repository_id", "project_id"], :name => "index_project_to_repositories_on_repository_id_and_project_id", :unique => true
|
||||
|
||||
create_table "projects", :force => true do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "owner_id"
|
||||
t.string "owner_type"
|
||||
t.string "visibility", :default => "open"
|
||||
t.text "description"
|
||||
t.string "ancestry"
|
||||
t.boolean "has_issues", :default => true
|
||||
t.boolean "has_wiki", :default => false
|
||||
t.string "srpm_file_name"
|
||||
t.string "srpm_content_type"
|
||||
t.integer "srpm_file_size"
|
||||
t.datetime "srpm_updated_at"
|
||||
t.string "srpm_content_type"
|
||||
t.boolean "has_wiki", :default => false
|
||||
t.string "default_branch", :default => "master"
|
||||
t.boolean "is_package", :default => true, :null => false
|
||||
t.integer "average_build_time", :default => 0, :null => false
|
||||
|
@ -420,8 +428,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.string "token"
|
||||
t.boolean "approved", :default => false
|
||||
t.boolean "rejected", :default => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "interest"
|
||||
t.text "more"
|
||||
t.string "language"
|
||||
|
@ -435,16 +443,16 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.string "actor_type"
|
||||
t.integer "target_id"
|
||||
t.string "target_type"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "role"
|
||||
end
|
||||
|
||||
create_table "repositories", :force => true do |t|
|
||||
t.string "description", :null => false
|
||||
t.integer "platform_id", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "name", :null => false
|
||||
t.boolean "publish_without_qa", :default => true
|
||||
end
|
||||
|
@ -458,8 +466,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.boolean "new_comment_reply", :default => true
|
||||
t.boolean "new_issue", :default => true
|
||||
t.boolean "issue_assign", :default => true
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "new_comment_commit_owner", :default => true
|
||||
t.boolean "new_comment_commit_repo_owner", :default => true
|
||||
t.boolean "new_comment_commit_commentor", :default => true
|
||||
|
@ -482,8 +490,8 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
create_table "subscribes", :force => true do |t|
|
||||
t.string "subscribeable_type"
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "status", :default => true
|
||||
t.integer "project_id"
|
||||
t.decimal "subscribeable_id", :precision => 50, :scale => 0
|
||||
|
@ -492,20 +500,17 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
create_table "users", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "reset_password_token"
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.datetime "remember_created_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.text "ssh_key"
|
||||
t.string "uname"
|
||||
t.string "role"
|
||||
t.string "language", :default => "en"
|
||||
t.integer "own_projects_count", :default => 0, :null => false
|
||||
t.string "confirmation_token"
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.text "professional_experience"
|
||||
t.string "site"
|
||||
t.string "company"
|
||||
|
@ -517,6 +522,9 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
|||
t.integer "failed_attempts", :default => 0
|
||||
t.string "unlock_token"
|
||||
t.datetime "locked_at"
|
||||
t.string "confirmation_token"
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.string "authentication_token"
|
||||
t.integer "build_priority", :default => 50
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Hooks" do
|
||||
describe "GET /hooks" do
|
||||
it "works! (now write some real specs)" do
|
||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
|
||||
get hooks_path
|
||||
response.status.should be(200)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Hook do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue