From 636ae022bfe8c17c0ea1082f104ccd274b757589 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 6 Mar 2014 17:24:33 +0600 Subject: [PATCH] [#247] remove private users --- .../platforms/private_users_controller.rb | 31 ------------ .../platforms/privates_controller.rb | 32 ------------ app/models/ability.rb | 3 -- app/models/event_log_observer.rb | 2 +- app/models/private_user.rb | 32 ------------ app/views/platforms/base/_sidebar.html.haml | 3 -- .../platforms/private_users/index.html.haml | 50 ------------------- config/locales/en.yml | 16 ------ config/locales/models/event_log.en.yml | 4 -- config/locales/models/event_log.ru.yml | 4 -- config/locales/models/platform.en.yml | 1 - config/locales/models/platform.ru.yml | 1 - config/locales/ru.yml | 16 ------ config/routes.rb | 2 - .../20140306102620_destroy_private_user.rb | 15 ++++++ db/schema.rb | 13 +---- .../private_users_controller_spec.rb | 5 -- .../platforms/privates_controller_spec.rb | 5 -- spec/factories/private_users.rb | 8 --- spec/models/cancan_spec.rb | 15 ------ spec/models/private_user_spec.rb | 5 -- 21 files changed, 18 insertions(+), 245 deletions(-) delete mode 100644 app/controllers/platforms/private_users_controller.rb delete mode 100644 app/controllers/platforms/privates_controller.rb delete mode 100644 app/models/private_user.rb delete mode 100644 app/views/platforms/private_users/index.html.haml create mode 100644 db/migrate/20140306102620_destroy_private_user.rb delete mode 100644 spec/controllers/platforms/private_users_controller_spec.rb delete mode 100644 spec/controllers/platforms/privates_controller_spec.rb delete mode 100644 spec/factories/private_users.rb delete mode 100644 spec/models/private_user_spec.rb diff --git a/app/controllers/platforms/private_users_controller.rb b/app/controllers/platforms/private_users_controller.rb deleted file mode 100644 index b36163cbb..000000000 --- a/app/controllers/platforms/private_users_controller.rb +++ /dev/null @@ -1,31 +0,0 @@ -class Platforms::PrivateUsersController < Platforms::BaseController - before_filter :authenticate_user! - before_filter :find_platform_and_private_users - - load_and_authorize_resource :platform - - def index - end - - def create - old_pair = PrivateUser.find_by_platform_id_and_user_id(params[:platform_id], current_user.id) - old_pair.destroy if old_pair - - @pair = PrivateUser.generate_pair(params[:platform_id], current_user.id) - @urpmi_list = @platform.urpmi_list(request.host, @pair) - redirect_to platform_private_users_path(params[:platform_id]), notice: I18n.t('flash.private_users', login: @pair[:login], password: @pair[:pass]) - end - - #def destroy - # user = PrivateUser.find(params[:id]) - # user.destroy - # redirect_to platform_private_users_path(params[:platform_id]) - #end - - protected - - def find_platform_and_private_users - @private_users = PrivateUser.where(platform_id: params[:platform_id]).paginate page: params[:page] - @platform = Platform.find(params[:platform_id]) - end -end diff --git a/app/controllers/platforms/privates_controller.rb b/app/controllers/platforms/privates_controller.rb deleted file mode 100644 index f1c129dca..000000000 --- a/app/controllers/platforms/privates_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -class Platforms::PrivatesController < Platforms::BaseController - require 'digest/sha2' - - before_filter :find_platform - before_filter :authenticate - - def show - file_name = "#{APP_CONFIG['root_path']}/platforms/#{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/models/ability.rb b/app/models/ability.rb index f7e22d199..e64376893 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -140,9 +140,6 @@ class Ability can([:create, :cancel, :update], ProductBuildList) {|pbl| can?(:update, pbl.product)} can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)} - can [:read, :create], PrivateUser, platform: {owner_type: 'User', owner_id: user.id} - can [:read, :create], PrivateUser, platform: {owner_type: 'Group', owner_id: user_group_ids} - can :read, Issue, project: {owner_type: 'User', owner_id: user.id} can :read, Issue, project: {owner_type: 'Group', owner_id: user_group_ids} can(:read, Issue, read_relations_for('issues', 'projects')) {|issue| can? :read, issue.project rescue nil} diff --git a/app/models/event_log_observer.rb b/app/models/event_log_observer.rb index 4258cd445..df47381c3 100644 --- a/app/models/event_log_observer.rb +++ b/app/models/event_log_observer.rb @@ -1,5 +1,5 @@ class EventLogObserver < ActiveRecord::Observer - observe :user, :private_user, :platform, :repository, :project, :product, :build_list, :product_build_list + observe :user, :platform, :repository, :project, :product, :build_list, :product_build_list def after_create(record) ActiveSupport::Notifications.instrument("event_log.observer", eventable: record) diff --git a/app/models/private_user.rb b/app/models/private_user.rb deleted file mode 100644 index 53413a17d..000000000 --- a/app/models/private_user.rb +++ /dev/null @@ -1,32 +0,0 @@ -class PrivateUser < ActiveRecord::Base - require 'digest/sha2' - - belongs_to :platform - belongs_to :user - - validate :login, uniqueness: true - - def event_log_message - {platform: platform.name, user: user.uname}.inspect - end - - class << self - def can_generate_more?(user_id, platform_id) - !PrivateUser.exists?(user_id: user_id, platform_id: platform_id) - end - - def generate_pair(platform_id, user_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, - user_id: user_id - ) - - {login: login, pass: pass} - end - end -end diff --git a/app/views/platforms/base/_sidebar.html.haml b/app/views/platforms/base/_sidebar.html.haml index 99818f383..567493589 100644 --- a/app/views/platforms/base/_sidebar.html.haml +++ b/app/views/platforms/base/_sidebar.html.haml @@ -34,6 +34,3 @@ = link_to t("layout.key_pairs.header"), platform_key_pairs_path(@platform) %li{class: (contr == :tokens) ? 'active' : ''} = link_to t('layout.tokens.header'), platform_tokens_path(@platform) - -#- if current_user.owner_of? @platform or current_user.admin? - %li{class: (act == :index && contr == :private_users) ? 'active' : ''} - = link_to t("layout.platforms.private_users"), platform_private_users_path(@platform) diff --git a/app/views/platforms/private_users/index.html.haml b/app/views/platforms/private_users/index.html.haml deleted file mode 100644 index ad70e003a..000000000 --- a/app/views/platforms/private_users/index.html.haml +++ /dev/null @@ -1,50 +0,0 @@ --set_meta_tags title: [title_object(current_user.repository), t('layout.personal_repositories.private_users')] -.block - .secondary-navigation - %ul.wat-cf - %li.first= link_to t("layout.personal_repositories.show"), personal_repository_path(current_user.personal_repository) - %li= link_to t("layout.personal_repositories.settings"), settings_personal_repository_path(current_user.personal_repository) - %li.active= link_to t("layout.personal_repositories.private_users"), platform_private_users_path(current_user.personal_platform) if current_user.personal_platform.hidden? - .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) - - - if @urpmi_list - = render 'shared/urpmi_list', urpmi_commands: @urpmi_list - .wat-cf - =# link_to image_tag("x.png", alt: t("layout.delete")) + " " + t("layout.delete"), platform_repository_path(@platform, @repository), method: "delete", class: "button", confirm: t("layout.repositories.confirm_delete") - %br - .inner - =t('layout.private_users.warning_message') - -.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 if PrivateUser.can_generate_more?(current_user.id, @platform.id) - .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 - = private_user.login - %td.last - #{link_to t("layout.private_users.regenerate_btn"), platform_private_users_path(@platform), method: :post, confirm: t("layout.private_users.confirm_regenerate")} - .actions-bar.wat-cf - .actions - = will_paginate @private_users \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 246f0a180..91e572fde 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -91,15 +91,6 @@ en: sign_in_header: Sign in sign_up_with: or sign in with - private_users: - list: List - new: New pair - list_header: Pair login/password - confirm_delete: Are you sure to delete this pair login/password? - confirm_regenerate: Are you sure to regenerate this pair login/password? - regenerate_btn: Regenerate - warning_message: Warning - Old data set as invalid when new data obtaining - collaborators: back_to_proj: Back to project edit: Edit list @@ -132,8 +123,6 @@ en: saved: Settings saved success save_error: Setting update error - private_users: "Login: %{login} Password: %{password}" - subscribe: saved: Subscription on notifications for this task is created saved_error: Subscription create error @@ -177,7 +166,6 @@ en: can_have_less_or_equal: You cannot have more than %{count} projects. models: - private_user: Private user product_build_list: Product build list attributes: @@ -195,10 +183,6 @@ en: new_build: Notify about my build tasks new_associated_build: Notify about associated with me build tasks - private_user: - login: Login - password: Password - arch: name: Name created_at: Created diff --git a/config/locales/models/event_log.en.yml b/config/locales/models/event_log.en.yml index b44100e0e..aca5e3f67 100644 --- a/config/locales/models/event_log.en.yml +++ b/config/locales/models/event_log.en.yml @@ -11,7 +11,6 @@ en: 'devise/sessions_controller': 'User Authentication' 'devise/passwords_controller': 'Password recovery' 'users/omniauth_callbacks_controller': 'External users authentication' - private_users_controller: 'access to private repositories' personal_repositories_controller: 'Personal repositories management' actions: 'devise/sessions_controller': @@ -27,9 +26,6 @@ en: create: 'sent to build' rpc_controller: xe_index: inquiry - private_users_controller: - create: 'given' - destroy: 'deleted' personal_repositories_controller: change_visibility: 'status change' create: 'created' diff --git a/config/locales/models/event_log.ru.yml b/config/locales/models/event_log.ru.yml index 8d4458cdc..d979d9f95 100644 --- a/config/locales/models/event_log.ru.yml +++ b/config/locales/models/event_log.ru.yml @@ -11,7 +11,6 @@ ru: 'devise/sessions_controller': 'Аутентификация пользователей' 'devise/passwords_controller': 'Восстановление пароля' 'users/omniauth_callbacks_controller': 'Внешняя аутентификация пользователей' - private_users_controller: 'Доступ к приватным репозиториям' personal_repositories_controller: 'Управление персональными репозиториями' actions: 'devise/sessions_controller': @@ -27,9 +26,6 @@ ru: create: 'отправлен на сборку' rpc_controller: xe_index: запрос - private_users_controller: - create: 'предоставлен' - destroy: 'удален' personal_repositories_controller: change_visibility: 'смена статуса' create: 'создано' diff --git a/config/locales/models/platform.en.yml b/config/locales/models/platform.en.yml index e59d5bc29..ebc845cb9 100644 --- a/config/locales/models/platform.en.yml +++ b/config/locales/models/platform.en.yml @@ -35,7 +35,6 @@ en: visibility: Visibility platform_type: Platform type distrib_type: Distribution type - private_users: Access data confirm_clone: Clone? clone: Clone delete_warning: Attention! Deleted platform can not be restored! diff --git a/config/locales/models/platform.ru.yml b/config/locales/models/platform.ru.yml index cea910b36..a3b38a16d 100644 --- a/config/locales/models/platform.ru.yml +++ b/config/locales/models/platform.ru.yml @@ -35,7 +35,6 @@ ru: visibility: Видимость platform_type: Тип платформы distrib_type: Тип дистрибутива - private_users: Данные для доступа confirm_clone: Клонировать? clone: Клонировать delete_warning: Внимание! Удаленная платформа восстановлению не подлежит. diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 7bf16e90a..eb2874fba 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -91,15 +91,6 @@ ru: sign_in_header: Вход в систему sign_up_with: или войти с помощью - private_users: - list: Список - new: Новая пара - list_header: Пары логин/пароль - confirm_delete: Вы уверены, что хотите удалить эту пару логин/пароль? - confirm_regenerate: Вы уверены, что хотите перегенерировать эту пару логин/пароль? - regenerate_btn: Перегенерировать - warning_message: Примечание - При получении новых данных старые становятся недействительными - collaborators: back_to_proj: Вернуться к проекту edit: Редактировать список @@ -132,8 +123,6 @@ ru: saved: Настройки успешно сохранены save_error: При обновлении настроек произошла ошибка - private_users: "Логин: %{login} Пароль: %{password}" - subscribe: saved: Вы подписаны на оповещения для этой задачи saved_error: При создании подписки произошла ошибка @@ -177,7 +166,6 @@ ru: can_have_less_or_equal: Нельзя иметь больше, чем %{count} проектов. models: - private_user: Приватный пользователь product_build_list: Сборочный лист продукта attributes: @@ -195,10 +183,6 @@ ru: new_build: Оповещать о моих сборочных заданиях new_associated_build: Оповещать о связанных со мной сборочных заданиях - private_user: - login: Логин - password: Пароль - arch: name: Название created_at: Создана diff --git a/config/routes.rb b/config/routes.rb index c12a6e131..6b4369d0d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -165,7 +165,6 @@ Rosa::Application.routes.draw do scope module: 'platforms' do resources :platforms, constraints: {id: Platform::NAME_PATTERN} do - resources :private_users, except: [:show, :destroy, :update] member do put :regenerate_metadata put :clear @@ -221,7 +220,6 @@ Rosa::Application.routes.draw do end resources :maintainers, only: [:index] end - match '/private/:platform_name/*file_path' => 'privates#show' resources :product_build_lists, only: [:index, :show] end diff --git a/db/migrate/20140306102620_destroy_private_user.rb b/db/migrate/20140306102620_destroy_private_user.rb new file mode 100644 index 000000000..0e57648f1 --- /dev/null +++ b/db/migrate/20140306102620_destroy_private_user.rb @@ -0,0 +1,15 @@ +class DestroyPrivateUser < ActiveRecord::Migration + def self.up + drop_table :private_users + end + + def self.down + create_table :private_users do |t| + t.integer :platform_id + t.string :login + t.string :password + t.integer :user_id + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9cb057529..b21cff4f7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140224134012) do +ActiveRecord::Schema.define(:version => 20140306102620) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -285,7 +285,6 @@ ActiveRecord::Schema.define(:version => 20140224134012) do t.string "arch_names" t.integer "user_id" t.boolean "auto_publish", :default => false, :null => false - t.integer "build_lists_count", :default => 0, :null => false t.boolean "stop_build", :default => false, :null => false t.text "projects_list" t.integer "missed_projects_count", :default => 0, :null => false @@ -295,6 +294,7 @@ ActiveRecord::Schema.define(:version => 20140224134012) do t.text "extra_repositories" t.text "extra_build_lists" t.boolean "increase_release_tag", :default => false, :null => false + t.integer "build_lists_count", :default => 0 end create_table "platform_arch_settings", :force => true do |t| @@ -329,15 +329,6 @@ ActiveRecord::Schema.define(:version => 20140224134012) do add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false - 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" - t.integer "user_id" - end - create_table "product_build_lists", :force => true do |t| t.integer "product_id" t.integer "status", :null => false diff --git a/spec/controllers/platforms/private_users_controller_spec.rb b/spec/controllers/platforms/private_users_controller_spec.rb deleted file mode 100644 index 6173681d8..000000000 --- a/spec/controllers/platforms/private_users_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe Platforms::PrivateUsersController do - -end diff --git a/spec/controllers/platforms/privates_controller_spec.rb b/spec/controllers/platforms/privates_controller_spec.rb deleted file mode 100644 index 5a8c7bd99..000000000 --- a/spec/controllers/platforms/privates_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe Platforms::PrivatesController do - -end diff --git a/spec/factories/private_users.rb b/spec/factories/private_users.rb deleted file mode 100644 index e761d80ab..000000000 --- a/spec/factories/private_users.rb +++ /dev/null @@ -1,8 +0,0 @@ -FactoryGirl.define do - factory :private_user do - login { FactoryGirl.generate(:string) } - password { FactoryGirl.generate(:string) } - association :platform, factory: :platform - association :user, factory: :user - end -end diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index f10dcc8f4..c3e0f56f3 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -130,21 +130,6 @@ describe CanCan do @ability.should_not be_able_to(:manage, RegisterRequest) end - context "private users relations" do - before(:each) do - @private_user = FactoryGirl.create(:private_user) - - @private_user.platform.owner = @user - @private_user.platform.save - end - - [:read, :create].each do |action| - it "should be able to #{ action } PrivateUser" do - @ability.should be_able_to(action, @private_user) - end - end - end - context 'as project collaborator' do before(:each) do @project = FactoryGirl.create(:project_with_commit) diff --git a/spec/models/private_user_spec.rb b/spec/models/private_user_spec.rb deleted file mode 100644 index afbac1006..000000000 --- a/spec/models/private_user_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe PrivateUser do - pending "add some examples to (or delete) #{__FILE__}" -end