before_filter :bf
def bf
- if Admin.count.to_i == 0 or License.count.to_i == 0
+ if Admin.count.to_i == 0 # or License.count.to_i == 0
if params[:controller] == 'system' and params[:action] == 'start'
else
redirect_to :controller => '/system', :action => 'start'
class LicenseGroupController < ApplicationController
+ before_filter :authenticate_admin!, :only => [:list, :browse]
+
+ # GET /license_groups
+ # GET /license_groups.json
+ def index
+ @license_groups = LicenseGroup.list({})
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @license_groups.to_json(LicenseGroup.list_json_opt) }
+ end
+ end
+
+ # GET /license_groups/1
+ # GET /license_groups/1.json
+ def show
+ @license_group = LicenseGroup.show(params[:id])
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @license_group.to_json(LicenseGroup.show_json_include_opt) }
+ end
+ end
+
+ def list
+ @license_groups = LicenseGroup.all
+
+ respond_to do |format|
+ format.html { render layout: 'system' }
+ end
+ end
+
+ def browse
+ @license_group = LicenseGroup.find(params[:id])
+
+ respond_to do |format|
+ format.html { render layout: 'system' }
+ end
+ end
end
class License < ActiveRecord::Base
+ belongs_to :license_group
has_one :original_license
has_one :common_license
validates :name, :presence => true, :length => {:maximum => 50}
class LicenseGroup < ActiveRecord::Base
+ has_many :licenses
+
validates :name, :presence => true, :length => {:maximum => 50}, :uniqueness => true
validates :classname, :presence => true, :length => {:maximum => 50}
validates :caption, :presence => true, :length => {:maximum => 30}
LicenseGroup.import_file(filename) {|name, attr| LicenseGroup.store(name, attr)}
end
+ def self.list opt = {}
+ opt.merge!(self.list_opt) unless opt[:include]
+ opt.merge!({:order => 'license_groups.name asc'})
+ LicenseGroup.find(:all, opt)
+ end
+
+ def self.list_opt
+ {:include => {:licenses => {}}}
+ end
+
+ def self.list_json_opt
+ {:include => {:licenses => {}}}
+ end
+
+ def self.show rid, opt = {}
+ r = LicenseGroup.find(rid, :include => self.show_include_opt(opt))
+# raise ActiveRecord::Forbidden unless c.visible?(au)
+ r
+ end
+
+ def self.show_include_opt opt = {}
+ res = {:licenses => {}}
+ res.push(opt[:include]) if opt[:include]
+ res
+ end
+
+ def self.show_json_include_opt
+ {:include => {:licenses => {}}}
+ end
+
end
--- /dev/null
+<div>
+<% if @license.common_license -%>
+ <%= link_to 'to common_licenses', :controller => 'common_licenses', :action => :browse, :id => @license.common_license.id %>
+<% else -%>
+ <%= link_to 'to original_licenses', :controller => 'original_licenses', :action => :browse, :id => @license.original_license.id %>
+<% end -%>
+</div>
+
+<%= link_to 'Back', :action => :list %>
--- /dev/null
+<h1>Listing license Groups</h1>
+
+<table>
+ <tr>
+ <th>id</th>
+ <th>name</th>
+ <th>classname</th>
+ <th>caption</th>
+ <th>url</th>
+ <th>created_at</th>
+ <th>updated_at</th>
+ <th></th>
+ </tr>
+
+<% @license_groups.each do |lg| %>
+ <tr>
+ <td><%= link_to lg.id, :action => :browse, :id => lg.id %></td>
+ <td><%= h lg.name %></td>
+ <td><%= h lg.classname %></td>
+ <td><%= h lg.caption %></td>
+ <td><%= h lg.url %></td>
+ <td><%= lg.created_at %></td>
+ <td><%= lg.updated_at %></td>
+ </tr>
+<% end -%>
+</table>
</tr>
<tr>
<td>
- <%= link_to 'lesences', :controller => 'licenses', :action => :list %>
+ <%= link_to 'licenses', :controller => 'licenses', :action => :list %>
</td>
</tr>
<tr>
<td>
- <%= link_to 'common lesences', :controller => 'common_licenses', :action => :list %>
- </td>
- </tr>
- <tr>
- <td>
- <%= link_to 'original lesences', :controller => 'original_licenses', :action => :list %>
+ <%= link_to 'license_groups', :controller => 'license_groups', :action => :list %>
</td>
</tr>
<tr>
get :browse
end
end
+ resources :license_groups do
+ collection do
+ get :index
+ get :show
+ get :list
+ get :browse
+ end
+ end
resources :original_licenses do
collection do
get :index
--- /dev/null
+{\r
+ "PublicDomain": {\r
+ "classname": "PublicDomain", \r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/"\r
+ },\r
+ "Unknown": {\r
+ "classname": "Unknown", \r
+ "caption": "Unknown owner", \r
+ "url": "http://test.uk/"\r
+ }\r
+}\r
end
end
+ describe '単体取得に於いて' do
+ before do
+ @lg = Factory :license_group
+ end
+ it '指定のコマを返す' do
+ l = LicenseGroup.show @lg.id
+ l.should eq @lg
+ end
+ end
+ describe '関連テーブルプションに於いて' do
+ context 'オプションがないとき' do
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.show_include_opt
+ r.has_key?(:licenses).should be_true
+ end
+ end
+ end
+ describe 'json単体出力オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = LicenseGroup.show_json_include_opt
+ r.has_key?(:include).should be_true
+ end
+ it '1つの項目を含んでいる' do
+ r = LicenseGroup.show_json_include_opt[:include]
+ r.should have(1).items
+ end
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.show_json_include_opt[:include]
+ r.has_key?(:licenses).should be_true
+ end
+ end
+ describe '一覧取得に於いて' do
+ before do
+ @lg = Factory :license_group
+ end
+ it 'リストを返す' do
+ l = LicenseGroup.list
+ l.should eq [@lg]
+ end
+ it '名前順で並んでいる' do
+ @lg2 = Factory :license_group, :name => "Z" + @lg.name, :url => 'http://test.ptn/10'
+ l = LicenseGroup.list
+ l.should eq [@lg, @lg2]
+ end
+ end
+ describe 'list関連テーブルプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = LicenseGroup.list_opt
+ r.has_key?(:include).should be_true
+ end
+ it '1つの項目を含んでいる' do
+ r = LicenseGroup.list_opt[:include]
+ r.should have(1).items
+ end
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.list_opt[:include]
+ r.has_key?(:licenses).should be_true
+ end
+ end
+ describe 'json一覧出力オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = LicenseGroup.list_json_opt
+ r.has_key?(:include).should be_true
+ end
+ it '1つの項目を含んでいる' do
+ r = LicenseGroup.list_json_opt[:include]
+ r.should have(1).items
+ end
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.list_json_opt[:include]
+ r.has_key?(:licenses).should be_true
+ end
+ end
+
end