diff --git a/app/controllers/private_users_controller.rb b/app/controllers/private_users_controller.rb new file mode 100644 index 000000000..0c8df627b --- /dev/null +++ b/app/controllers/private_users_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/privates_controller.rb b/app/controllers/privates_controller.rb new file mode 100644 index 000000000..b014f491f --- /dev/null +++ b/app/controllers/privates_controller.rb @@ -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 diff --git a/app/helpers/private_users_helper.rb b/app/helpers/private_users_helper.rb new file mode 100644 index 000000000..c8c63083d --- /dev/null +++ b/app/helpers/private_users_helper.rb @@ -0,0 +1,2 @@ +module PrivateUsersHelper +end diff --git a/app/helpers/privates_helper.rb b/app/helpers/privates_helper.rb new file mode 100644 index 000000000..d4e240ef7 --- /dev/null +++ b/app/helpers/privates_helper.rb @@ -0,0 +1,2 @@ +module PrivatesHelper +end diff --git a/app/models/private_user.rb b/app/models/private_user.rb new file mode 100644 index 000000000..dccdc96db --- /dev/null +++ b/app/models/private_user.rb @@ -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 \ No newline at end of file diff --git a/app/views/platforms/show.html.haml b/app/views/platforms/show.html.haml index 3cd62b70a..6c92c6251 100644 --- a/app/views/platforms/show.html.haml +++ b/app/views/platforms/show.html.haml @@ -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 diff --git a/app/views/private_users/index.html.haml b/app/views/private_users/index.html.haml new file mode 100644 index 000000000..d43dd15d2 --- /dev/null +++ b/app/views/private_users/index.html.haml @@ -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   + - @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 \ No newline at end of file diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 796e2d360..d5f7381b9 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -43,6 +43,12 @@ ru: sessions: sign_in_header: Вход в систему + private_users: + list: Список + new: Новая пара + list_header: Пары логин/пароль + confirm_delete: Вы уверены, что хотите удалить эту пару логин/пароль? + platforms: list: Список new: Создать @@ -67,6 +73,7 @@ ru: visibility: Видимость platform_type: Тип платформы distrib_type: Тип дистрибутива + private_users: Пользователи приватного репозитория repositories: list: Список @@ -265,6 +272,10 @@ ru: download: Статистика attributes: + private_user: + login: Логин + password: Пароль + repository: name: Название platform_id: Платформа diff --git a/config/routes.rb b/config/routes.rb index 9c0cc90c8..ccd1c22d0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -40,8 +40,12 @@ Rosa::Application.routes.draw do # end # end # end + #resources :privates + match '/private/:platform_name/*file_path' => 'privates#show' resources :platforms do + resources :private_users + member do get 'freeze' get 'unfreeze' diff --git a/db/migrate/20111017112255_create_private_users.rb b/db/migrate/20111017112255_create_private_users.rb new file mode 100644 index 000000000..cb7eb9700 --- /dev/null +++ b/db/migrate/20111017112255_create_private_users.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 5593cd37c..2723b29ad 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -123,6 +123,14 @@ ActiveRecord::Schema.define(:version => 20111018102655) do t.string "distrib_type" 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 diff --git a/spec/controllers/private_users_controller_spec.rb b/spec/controllers/private_users_controller_spec.rb new file mode 100644 index 000000000..54140eff5 --- /dev/null +++ b/spec/controllers/private_users_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe PrivateUsersController do + +end diff --git a/spec/controllers/privates_controller_spec.rb b/spec/controllers/privates_controller_spec.rb new file mode 100644 index 000000000..fe2affa24 --- /dev/null +++ b/spec/controllers/privates_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe PrivatesController do + +end diff --git a/spec/helpers/private_users_helper_spec.rb b/spec/helpers/private_users_helper_spec.rb new file mode 100644 index 000000000..2ac72aba5 --- /dev/null +++ b/spec/helpers/private_users_helper_spec.rb @@ -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 diff --git a/spec/helpers/privates_helper_spec.rb b/spec/helpers/privates_helper_spec.rb new file mode 100644 index 000000000..3a17aad73 --- /dev/null +++ b/spec/helpers/privates_helper_spec.rb @@ -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 diff --git a/spec/models/private_user_spec.rb b/spec/models/private_user_spec.rb new file mode 100644 index 000000000..afbac1006 --- /dev/null +++ b/spec/models/private_user_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe PrivateUser do + pending "add some examples to (or delete) #{__FILE__}" +end