[refs #1923] Add private repositories to project

This commit is contained in:
santaux 2011-10-18 17:47:17 +04:00
parent d57347648f
commit 5f17928423
16 changed files with 212 additions and 1 deletions

View File

@ -0,0 +1,17 @@
class PrivateUsersController < ApplicationController
def index
@private_users = PrivateUser.where(:platform_id => params[:platform_id]).paginate :page => params[:page]
@platform = Platform.find(params[:platform_id])
end
def create
pair = PrivateUser.generate_pair(params[:platform_id])
redirect_to platform_private_users_path(params[:platform_id]),
:notice => "Логин: #{ pair[:login] } Пароль: #{ pair[:pass] }"
end
def destroy
PrivateUser.find(params[:id]).destroy
redirect_to platform_private_users_path(params[:platform_id])
end
end

View File

@ -0,0 +1,32 @@
class PrivatesController < ApplicationController
require 'digest/sha2'
before_filter :find_platform
before_filter :authenticate
def show
file_name = "#{APP_CONFIG['private_repo_path']}/#{params[:platform_name]}/#{params[:file_path]}"
if File.directory?(file_name) || !File.exists?(file_name)
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
send_file file_name
end
end
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
PrivateUser.exists?(
:login => username,
:password => Digest::SHA2.new.hexdigest(password),
:platform_id => @platform.try(:id)
)
end
end
def find_platform
@platform = Platform.find_by_name(params[:platform_name])
end
end

View File

@ -0,0 +1,2 @@
module PrivateUsersHelper
end

View File

@ -0,0 +1,2 @@
module PrivatesHelper
end

View File

@ -0,0 +1,21 @@
class PrivateUser < ActiveRecord::Base
require 'digest/sha2'
require 'active_support/secure_random'
validate :login, :uniqueness => true
class << self
def generate_pair(platform_id)
login = "login_#{ActiveSupport::SecureRandom.hex(16)}"
pass = "pass_#{ActiveSupport::SecureRandom.hex(16)}"
PrivateUser.create(
:login => login,
:password => Digest::SHA2.new.hexdigest(pass),
:platform_id => platform_id
)
{:login => login, :pass => pass}
end
end
end

View File

@ -4,6 +4,7 @@
%li.first= link_to t("layout.platforms.list"), platforms_path
%li= link_to t("layout.platforms.new"), new_platform_path
%li.active= link_to t("layout.platforms.show"), platform_path
%li= link_to t("layout.platforms.private_users"), platform_private_users_path(@platform)
.content
.inner
%p

View File

@ -0,0 +1,43 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first=# link_to t("layout.repositories.list"), platform_path(@platform) + "#repositories"
%li=# link_to t("layout.repositories.new"), new_platform_repository_path(@platform)
%li.active=# link_to t("layout.repositories.show"), platform_repository_path(@platform, @repository)
.content
.inner
%p
%b
= t("activerecord.attributes.platform.name")
\:
= @platform.name
%p
%b
= t("activerecord.attributes.repository.platform")
\:
= link_to @platform.name, platform_path(@platform)
.wat-cf
=# link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_repository_path(@platform, @repository), :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete")
.block
.secondary-navigation
%ul.wat-cf
%li.first.active= link_to t("layout.private_users.list"), platform_private_users_path(@platform)
%li= link_to t("layout.private_users.new"), platform_private_users_path(@platform), :method => :post
.content
%h2.title
= t("layout.private_users.list_header")
.inner
%table.table
%tr
%th.first= t("activerecord.attributes.private_user.login")
%th.last &nbsp;
- @private_users.each do |private_user|
%tr{:class => cycle("odd", "even")}
%td
= link_to private_user.login, platform_private_user_path(@platform, private_user)
%td.last
#{link_to t("layout.delete"), platform_private_user_path(@platform, private_user), :method => :delete, :confirm => t("layout.private_users.confirm_delete")}
.actions-bar.wat-cf
.actions
= will_paginate @private_users

View File

@ -37,6 +37,12 @@ ru:
sessions:
sign_in_header: Вход в систему
private_users:
list: Список
new: Новая пара
list_header: Пары логин/пароль
confirm_delete: Вы уверены, что хотите удалить эту пару логин/пароль?
platforms:
list: Список
new: Создать
@ -57,6 +63,7 @@ ru:
released_suffix: (выпущена)
confirm_delete: Вы уверены, что хотите удалить эту платформу?
current_platform_header: Текущая платформа
private_users: Пользователи приватного репозитория
repositories:
list: Список
@ -230,6 +237,10 @@ ru:
build_list_item: Элемент сборочного листа
attributes:
private_user:
login: Логин
password: Пароль
repository:
name: Название
platform_id: Платформа

View File

@ -4,7 +4,12 @@ Rosa::Application.routes.draw do
end
resources :users
#resources :privates
match '/private/:platform_name/*file_path' => 'privates#show'
resources :platforms do
resources :private_users
member do
get 'freeze'
get 'unfreeze'

View File

@ -0,0 +1,14 @@
class CreatePrivateUsers < ActiveRecord::Migration
def self.up
create_table :private_users do |t|
t.integer :platform_id
t.string :login
t.string :password
t.timestamps
end
end
def self.down
drop_table :private_users
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20111011200645) do
ActiveRecord::Schema.define(:version => 20111017112255) do
create_table "arches", :force => true do |t|
t.string "name", :null => false
@ -84,6 +84,16 @@ ActiveRecord::Schema.define(:version => 20111011200645) do
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
create_table "downloads", :force => true do |t|
t.string "name", :null => false
t.string "version"
t.string "distro"
t.string "platform"
t.integer "counter", :default => 0
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "platforms", :force => true do |t|
t.string "name"
t.string "unixname"
@ -93,6 +103,14 @@ ActiveRecord::Schema.define(:version => 20111011200645) do
t.boolean "released", :default => false
end
create_table "private_users", :force => true do |t|
t.integer "platform_id"
t.string "login"
t.string "password"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "products", :force => true do |t|
t.string "name", :null => false
t.integer "platform_id", :null => false

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe PrivateUsersController do
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe PrivatesController do
end

View File

@ -0,0 +1,15 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the PrivateUsersHelper. For example:
#
# describe PrivateUsersHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe PrivateUsersHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,15 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the PrivatesHelper. For example:
#
# describe PrivatesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe PrivatesHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe PrivateUser do
pending "add some examples to (or delete) #{__FILE__}"
end