From f1f6d7e7ac16645ad9a01674161db2ed34314610 Mon Sep 17 00:00:00 2001 From: Wedge Date: Tue, 2 Mar 2021 16:05:57 +0300 Subject: [PATCH] Remove stuff --- .../platforms/key_pairs_controller.rb | 31 ------- app/helpers/facebook_helper.rb | 60 -------------- app/models/key_pair.rb | 81 ------------------- app/models/platform.rb | 1 - app/models/user.rb | 2 - app/views/platforms/base/_submenu.html.slim | 5 -- app/views/platforms/key_pairs/_list.html.slim | 18 ----- app/views/platforms/key_pairs/_new.html.slim | 9 --- app/views/platforms/key_pairs/index.html.slim | 9 --- app/views/shared/_header.html.slim | 14 ---- config/routes.rb | 1 - 11 files changed, 231 deletions(-) delete mode 100644 app/controllers/platforms/key_pairs_controller.rb delete mode 100644 app/helpers/facebook_helper.rb delete mode 100644 app/models/key_pair.rb delete mode 100644 app/views/platforms/key_pairs/_list.html.slim delete mode 100644 app/views/platforms/key_pairs/_new.html.slim delete mode 100644 app/views/platforms/key_pairs/index.html.slim delete mode 100644 app/views/shared/_header.html.slim diff --git a/app/controllers/platforms/key_pairs_controller.rb b/app/controllers/platforms/key_pairs_controller.rb deleted file mode 100644 index 499c613da..000000000 --- a/app/controllers/platforms/key_pairs_controller.rb +++ /dev/null @@ -1,31 +0,0 @@ -class Platforms::KeyPairsController < Platforms::BaseController - before_action :authenticate_user! - - def index - @key_pair = KeyPair.new - end - - def create - @key_pair = KeyPair.new subject_params(KeyPair) - @key_pair.user_id = current_user.id - authorize @key_pair - if @key_pair.save - flash[:notice] = t('flash.key_pairs.saved') - redirect_to platform_key_pairs_path(@key_pair.repository.platform) and return - else - flash[:error] = t('flash.key_pairs.save_error') - end - render :index - end - - def destroy - authorize @key_pair = @platform.key_pairs.find(params[:id]) - if @key_pair.destroy - flash[:notice] = t('flash.key_pairs.destroyed') - else - flash[:error] = t('flash.key_pairs.destroy_error') - end - - redirect_to platform_key_pairs_path(@key_pair.repository.platform) - end -end diff --git a/app/helpers/facebook_helper.rb b/app/helpers/facebook_helper.rb deleted file mode 100644 index 06c4d1a7c..000000000 --- a/app/helpers/facebook_helper.rb +++ /dev/null @@ -1,60 +0,0 @@ -module FacebookHelper - - # Returns a facebook-specific image for the current page. - def facebook_meta_image - resource = get_resource - @fb_meta_image ||= avatar_url(resource, :big) if resource.respond_to?(:avatar) - @fb_meta_image ||= asset_url('fb-image.png') - - @fb_meta_image - end - - # Returns a facebook-specific URL for the current page. - def facebook_meta_url - @fb_meta_url ||= fb_like_url(get_resource) - end - - # Returns the facebook application id. - def facebook_meta_app_id - APP_CONFIG['keys']['facebook']['id'] - end - - # Returns the facebook site name - used for the site:og_name meta tag. - def facebook_site_name - APP_CONFIG['project_name'] - end - - # Creates a 'like' URL for the given object instance. - def fb_like_url(object=nil) - # All likes for resources go to referrers#like, which redirects them - # to the appropriate target. - begin - # Make sure we're using the correct domain. This should happen automatically, - # but is a bit flaky in cucumber so set it explicitly to be safe. - #domain = current_site.present? ? current_site.domain : request.host - url = object.respond_to?(:fb_like_url) ? - object.fb_like_url : polymorphic_url(object)#, host: domain) - rescue - end if object - url ||= request.url - # Clean up unnecessary params - url.gsub!(/\?.*/, '') - url << "?page=#{params[:page]}" if params[:page].to_i > 1 - url - end - - protected - - # Gets the current resource. - def get_resource - case controller - when Groups::BaseController - @group - when Users::BaseController - @user - else - instance_variable_get "@#{controller_name.singularize}" - end - end - -end diff --git a/app/models/key_pair.rb b/app/models/key_pair.rb deleted file mode 100644 index 1967885bf..000000000 --- a/app/models/key_pair.rb +++ /dev/null @@ -1,81 +0,0 @@ -require 'open3' -class KeyPair < ActiveRecord::Base - belongs_to :repository - belongs_to :user - - attr_accessor :fingerprint - attr_encrypted :secret, key: APP_CONFIG['keys']['key_pair_secret_key'] - - validates :repository, :user, presence: true - validates :secret, :public, presence: true, length: { maximum: 10000 }, on: :create - - validates :repository_id, uniqueness: { message: I18n.t("activerecord.errors.key_pair.repo_key_exists") } - validate :check_keys - - before_create { |record| record.key_id = @fingerprint } - after_create { |record| record.repository.resign } - - protected - - def check_keys - dir = Dir.mktmpdir 'keys-', APP_CONFIG['tmpfs_path'] - begin - %w(pubring secring).each do |kind| - filename = "#{dir}/#{kind}" - open("#{filename}.txt", "w") { |f| f.write self.send(kind == 'pubring' ? :public : :secret) } - system "gpg --homedir #{dir} --dearmor < #{filename}.txt > #{filename}.gpg" - end - - public_key = get_info_of_key "#{dir}/pubring.gpg" - secret_key = get_info_of_key "#{dir}/secring.gpg" - - if correct_key?(public_key, :public) & correct_key?(secret_key, :secret) - if public_key[:fingerprint] != secret_key[:fingerprint] - errors.add :secret, I18n.t('activerecord.errors.key_pair.wrong_keys') - else - stdin, stdout, stderr = Open3.popen3("echo '\n\n\n\n\nsave' | LC_ALL=en gpg --command-fd 0 --homedir #{dir} --edit-key #{secret_key[:keyid]} passwd") - output = stderr.read - if output =~ /Invalid\spassphrase/ - errors.add :secret, I18n.t('activerecord.errors.key_pair.key_has_passphrase') - else - @fingerprint = secret_key[:fingerprint] - end - end - end - ensure - # remove the directory. - FileUtils.remove_entry_secure dir - end - end - - def correct_key?(info, field) - if info.empty? || info[:type].blank? || info[:fingerprint].blank? || info[:keyid].blank? - errors.add field, I18n.t('activerecord.errors.key_pair.wrong_key') - return false - else - if info[:type] != field - errors.add field, I18n.t("activerecord.errors.key_pair.wrong_#{field}_key") - return false - end - end - return true - end - - def get_info_of_key(file_path) - results = {} - str = %x[ gpg --with-fingerprint #{file_path} | sed -n 1,2p] - info = str.strip.split("\n") - if info.size == 2 - results[:fingerprint] = info[1].gsub(/.*\=/, '').strip.gsub(/\s/, ':') - - results[:type] = info[0] =~ /^pub\s/ ? :public : nil - results[:type] ||= info[0] =~ /^sec\s/ ? :secret : nil - - if keyid = info[0].match(/\/[\w]+\s/) - results[:keyid] = keyid[0].strip[1..-1] - end - end - return results - end - -end diff --git a/app/models/platform.rb b/app/models/platform.rb index 8b30a6be8..6c043930f 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -34,7 +34,6 @@ class Platform < ActiveRecord::Base belongs_to :owner, polymorphic: true has_many :repositories, dependent: :destroy - has_many :key_pairs, through: :repositories has_many :projects, through: :repositories has_many :products, dependent: :destroy diff --git a/app/models/user.rb b/app/models/user.rb index 43a9d6494..9bed2e460 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,8 +35,6 @@ class User < Avatar has_many :own_groups, foreign_key: :owner_id, class_name: 'Group', dependent: :destroy has_many :own_platforms, as: :owner, class_name: 'Platform', dependent: :destroy - has_many :key_pairs - validates :uname, presence: true, uniqueness: { case_sensitive: false }, format: { with: /\A#{NAME_REGEXP.source}\z/ }, diff --git a/app/views/platforms/base/_submenu.html.slim b/app/views/platforms/base/_submenu.html.slim index fc67bb5d9..e88fb4fb8 100644 --- a/app/views/platforms/base/_submenu.html.slim +++ b/app/views/platforms/base/_submenu.html.slim @@ -28,8 +28,3 @@ - if policy(@platform).local_admin_manage? li class=('active' if act == :members && contr == :platforms) = link_to t("layout.platforms.members"), members_platform_path(@platform) - / - if policy(@platform).edit? - / li class=('active' if contr == :key_pairs) - / = link_to t("layout.key_pairs.header"), platform_key_pairs_path(@platform) - / li class=('active' if contr == :tokens) - / = link_to t('layout.tokens.header'), platform_tokens_path(@platform) diff --git a/app/views/platforms/key_pairs/_list.html.slim b/app/views/platforms/key_pairs/_list.html.slim deleted file mode 100644 index 2c4889ed1..000000000 --- a/app/views/platforms/key_pairs/_list.html.slim +++ /dev/null @@ -1,18 +0,0 @@ -table.table.table-striped - thead - tr - th= t("activerecord.attributes.key_pair.repository_id") - th= t("activerecord.attributes.key_pair.key_id") - th= t("activerecord.attributes.key_pair.user_id") - th= t("layout.delete") - tbody - - @platform.repositories.each do |repository| - - if repository.key_pair - tr - td= repository.name - td= repository.key_pair.key_id - td= link_to repository.key_pair.user.fullname, user_path(repository.key_pair.user) - td.buttons - - if policy(repository.key_pair).destroy? - = link_to platform_key_pair_path(@platform, repository.key_pair), method: :delete, data: { confirm: t("layout.key_pairs.confirm_delete") } do - span.glyphicon.glyphicon-remove diff --git a/app/views/platforms/key_pairs/_new.html.slim b/app/views/platforms/key_pairs/_new.html.slim deleted file mode 100644 index f6409ffdf..000000000 --- a/app/views/platforms/key_pairs/_new.html.slim +++ /dev/null @@ -1,9 +0,0 @@ -h3 - = t("layout.key_pairs.header") - -= simple_form_for @key_pair, url: platform_key_pairs_path(@platform) do |f| - = f.input :public, as: :text - = f.input :secret, as: :text - = f.input :repository_id, collection: key_pair_repository_options(@platform) - - = submit_button_tag \ No newline at end of file diff --git a/app/views/platforms/key_pairs/index.html.slim b/app/views/platforms/key_pairs/index.html.slim deleted file mode 100644 index 9a5d0fe24..000000000 --- a/app/views/platforms/key_pairs/index.html.slim +++ /dev/null @@ -1,9 +0,0 @@ -- set_meta_tags title: [title_object(@platform), t('layout.key_pairs.header')] -= render 'platforms/base/submenu' - -.container.col-md-offset-2.col-md-8 - .row - - if policy(@platform).edit? - = render 'new' - hr - = render 'list' diff --git a/app/views/shared/_header.html.slim b/app/views/shared/_header.html.slim deleted file mode 100644 index af9b33b2d..000000000 --- a/app/views/shared/_header.html.slim +++ /dev/null @@ -1,14 +0,0 @@ -/ link rel='canonical' href=facebook_meta_url -/ meta property='og:title' content=facebook_meta_title -/ meta property='og:type' content='website' -/ meta property='og:url' content=facebook_meta_url -/ meta property='og:image' content=facebook_meta_image -/ meta property='og:site_name' content=facebook_site_name -/ meta property='fb:app_id' content=facebook_meta_app_id -/ meta property='og:description' content=facebook_meta_description -/ meta name='Description' content=facebook_meta_description - -/ meta property='twitter:card' content='summary' -/ meta property='twitter:site' content='@abf_io' -/ meta property='twitter:image' content=facebook_meta_image -/ meta property='twitter:url' content=facebook_meta_url diff --git a/config/routes.rb b/config/routes.rb index 27903a5e1..ce636f330 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -174,7 +174,6 @@ Rails.application.routes.draw do put :sync_lock_file end end - resources :key_pairs, only: [:create, :index, :destroy] resources :tokens, only: [:create, :index, :show, :new] do member do post :withdraw