From 129212129b305942725885edf6ab8a1f596815e4 Mon Sep 17 00:00:00 2001 From: Wedge Date: Tue, 2 Mar 2021 09:51:25 +0300 Subject: [PATCH] Remove contacts --- app/controllers/contacts_controller.rb | 28 ----- app/mailers/feedback_mailer.rb | 34 ------- app/models/feedback.rb | 101 ------------------- app/views/layouts/menu/_new_bottom.html.slim | 2 - config/routes.rb | 4 - 5 files changed, 169 deletions(-) delete mode 100644 app/controllers/contacts_controller.rb delete mode 100644 app/mailers/feedback_mailer.rb delete mode 100644 app/models/feedback.rb diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb deleted file mode 100644 index 8e76536db..000000000 --- a/app/controllers/contacts_controller.rb +++ /dev/null @@ -1,28 +0,0 @@ -class ContactsController < ApplicationController - skip_after_action :verify_authorized - - def new - @form = Feedback.new(current_user) - end - - def create - @form = Feedback.new(feedback_params) - if @form.perform_send - flash[:notice] = I18n.t("flash.contact.success") - redirect_to sended_contact_path - else - flash[:error] = I18n.t("flash.contact.error") - render :new and return - end - end - - def sended - end - - private - - def feedback_params - params[:feedback].permit(:name, :email, :subject, :message) - end - -end diff --git a/app/mailers/feedback_mailer.rb b/app/mailers/feedback_mailer.rb deleted file mode 100644 index c9150251d..000000000 --- a/app/mailers/feedback_mailer.rb +++ /dev/null @@ -1,34 +0,0 @@ -class FeedbackMailer < ActionMailer::Base - FBM_CONFIG = APP_CONFIG['feedback'] - - default to: FBM_CONFIG['email'], - cc: FBM_CONFIG['cc'], - bcc: FBM_CONFIG['bcc'] - default_url_options.merge!(protocol: 'https') if APP_CONFIG['mailer_https_url'] - -# include Resque::Mailer # send email async - - def feedback_form_send(form_data) - @data = Feedback.new(form_data) - - from = "#{@data.name} <#{@data.email}>" - subj = prepare_subject(@data.subject) - - mail from: from, subject: subj - end - - protected - - def prepare_subject(subject) - res = '' - res << affix(FBM_CONFIG['subject_prefixes']) - res << subject - res << affix(FBM_CONFIG['subject_postfixes']) - res = res.strip.gsub(/\s+/, ' ') - res - end - - def affix(affixes) - ' %s ' % Array(affixes).map{|e| "[#{e}]"}.join - end -end diff --git a/app/models/feedback.rb b/app/models/feedback.rb deleted file mode 100644 index 6519f0e18..000000000 --- a/app/models/feedback.rb +++ /dev/null @@ -1,101 +0,0 @@ -# This class is based on -# https://github.com/rails/rails/blob/4da6e1cce2833474034fda0cbb67b2cc35e828da/activerecord/lib/active_record/validations.rb - -class Feedback - include ActiveModel::Conversion - include ActiveModel::Validations - include ActiveModel::Serializers::JSON - extend ActiveModel::Naming - - self.include_root_in_json = false - - attr_accessor :name, :email, :subject, :message - - validates :name, :subject, :message, presence: true - validates :email, presence: true, - format: { with: /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/, - allow_blank: false } - - def initialize(args = {}, options = {}) - return args.dup if args.is_a? Feedback - if args.respond_to? :name and args.respond_to? :email - self.name, self.email = args.name, args.email - elsif args.respond_to? :each_pair - args.each_pair do |k, v| - send("#{k}=", v) - end - else - return false - end - end - - # FIXME: Maybe rename to `save`? - def perform_send(options = {}) - perform_validations(options) ? real_send : false - end - - def perform_send!(options={}) - perform_validations(options) ? real_send : raise(ActiveRecord::RecordInvalid.new(self)) - end - - def new_record? - true - end - - def persisted? - false - end - - def message_with_links - message.to_s.dup.auto_link - end - - def attributes - %w{ name email subject message }.inject({}) do |h, e| - h.merge(e => send(e)) - end - end - - def to_s - str = %w{ name email subject message }.map do |e| - "#{e}: #{ send(e).inspect }" - end.join(', ') - return "#<#{self.class} #{str}>" - end - - class << self - - def create(attributes = nil, options = {}, &block) - do_create(attributes, options, false, &block) - end - - def create!(attributes = nil, options = {}, &block) - do_create(attributes, options, true, &block) - end - - protected - - def do_create(attributes = nil, options = {}, bang = false, &block) - if attributes.is_a?(Array) - attributes.collect { |attr| do_create(attr, options, bang, &block) } - else - object = new(attributes, options) - yield(object) if block_given? - bang ? object.perform_send! : object.perform_send - object - end - end - - end - - protected - - def real_send - FeedbackMailer.feedback_form_send(self).deliver - end - - def perform_validations(options={}) - perform_validation = options[:validate] != false - perform_validation ? valid?(options[:context]) : true - end -end diff --git a/app/views/layouts/menu/_new_bottom.html.slim b/app/views/layouts/menu/_new_bottom.html.slim index 5e7762e63..a9c618fcf 100644 --- a/app/views/layouts/menu/_new_bottom.html.slim +++ b/app/views/layouts/menu/_new_bottom.html.slim @@ -4,6 +4,4 @@ .col-xs-4 = link_to t('bottom_menu.contacts'), t('bottom_menu.contacts_url') .col-xs-4 - = link_to t('bottom_menu.support'), contact_url - .col-xs-12 = link_to t('bottom_menu.tos'), 'https://www.openmandriva.org/tos' diff --git a/config/routes.rb b/config/routes.rb index 685fdb32d..27903a5e1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,10 +15,6 @@ Rails.application.routes.draw do match '/robots.txt' => 'sitemap#robots', via: [:get, :post, :head], as: :robots resources :statistics, only: [:index] - resource :contact, only: [:new, :create, :sended] do - get '/' => 'contacts#new' - get :sended - end devise_scope :user do get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'