Skip to content

Instantly share code, notes, and snippets.

@sunny4381
Last active April 13, 2024 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sunny4381/2c30fc42375c7ff049686a518ae29d1b to your computer and use it in GitHub Desktop.
Save sunny4381/2c30fc42375c7ff049686a518ae29d1b to your computer and use it in GitHub Desktop.
port = ENV.fetch('port', 3000).to_i
SITE_ALLOWED = begin
fields = []
# 基本情報
fields += %w[_id id name host domains subdir parent_id domains_with_subdir group_ids partner_site_
ids]
# ページ設定
fields += %w[auto_keywords keywords auto_description max_name_length]
# モバイル設定
fields += %w[mobile_state mobile_size mobile_location mobile_css]
# オープンデータ設定
fields += %w[dataset_workflow_route_id app_workflow_route_id idea_workflow_route_id dataset_state
app_state idea_state anti_bot_methods]
# エディタ設定
fields += %w[color_button editor_css_path syntax_check]
# ロゴ設定
fields += %w[logo_application_name logo_application_image_id]
# システム
fields += %w[created updated]
fields.freeze
end
USER_ALLOWED = begin
fields = []
# 基本情報
fields += %w[_id id name kana uid organization_uid email type account_start_date account_expiratio
n_date title_ids login_roles]
fields += %w[initial_password_warning session_lifetime restriction lock_state deletion_lock_state
organization_id group_ids]
# LDAP
fields += %w[ldap_dn]
# ロール
fields += %w[sys_role_ids cms_role_ids gws_role_ids webmail_role_ids]
# システム
fields += %w[created updated]
fields.freeze
end
GROUP_ALLOWED = begin
fields = []
# 基本情報
fields += %w[_id id name order activation_date expiration_date domains gws_use upload_policy]
# LDAP
fields += %w[ldap_dn ldap_import_id]
# Contact::Addon::Group
fields += %w[contact_groups contact_group_name contact_tel contact_fax contact_email contact_link_url contact_link_name]
# システム
fields += %w[created updated]
fields.freeze
end
# サイトのリセット
Cms::Site.all.unscoped.each do |site|
unset_fields = site.attributes.keys.reject { |k| SITE_ALLOWED.include?(k) }
site.unset(*unset_fields.map(&:to_sym)) if unset_fields.present?
site.reload
if site.parent.present?
site.domains = [ "#{site.parent.host}.example.jp:#{port}" ]
else
site.domains = [ "#{site.host}.example.jp:#{port}" ]
end
# HTTPS
site.https = "disabled"
# マイページドメイン
site.mypage_scheme = "http"
site.mypage_domain = "localhost:#{port}"
# 地図
# site.map_api = "openlayers" # クローン元と同じにする必要あり。"OpenLayers" へリセットしてはいけない。
site.map_api_key = nil
# 翻訳
if site.respond_to?(:translate_api)
site.translate_api = nil
site.translate_microsoft_api_key = nil
site.translate_google_api_project_id = nil
site.translate_google_api_credential_file = nil
end
site.save!
end
# ユーザーのリセット
Cms::User.all.unscoped.each do |user|
unset_fields = user.attributes.keys.reject { |k| USER_ALLOWED.include?(k) }
user.unset(*unset_fields.map(&:to_sym)) if unset_fields.present?
user.reload
# メールアドレス: 誤ってメールが送られないようにする。
user.email = "m-#{user.id}@example.jp" if user.email.present? && !user.email.end_with?('@example.jp')
# パスワード
user.in_password = "pass"
user.save!
# validation エラーが発生する場合は、上をコメントアウトして、下を有効にする
# user.save!(validate: false)
end
# グループのリセット
Cms::Group.all.unscoped.each do |group|
unset_fields = group.attributes.keys.reject { |k| GROUP_ALLOWED.include?(k) }
group.unset(*unset_fields.map(&:to_sym)) if unset_fields.present?
group.reload
# メールアドレス: 誤ってメールが送られないようにする。
group.contact_email = "m-#{group.id}@example.jp" if group.contact_email.present? && !group.contact_email.end_with?('@example.jp')
if group.respond_to?(:contact_groups) && group.contact_groups.count > 0
contact_groups = group.contact_groups.to_a
contact_groups = contact_groups.dup
contact_groups.map! do |contact|
contact.contact_email = "m-#{contact.id}@example.jp" if contact.contact_email.present? && !contact.contact_email.end_with?('@example.jp')
contact
end
group.contact_groups = contact_groups
end
group.save!
end
# # メンバーのパスワードリセット
# Cms::Member.all.where(state: 'enabled').exists(oauth_type: 0).each do |member|
# member.set(password: SS::Crypt.crypt('abc123'))
# end
#
# # メンバーの email リセット: 誤ってメールが送られないようにする。
# Cms::Member.all.each do |member|
# next if member.email.blank?
# next if member.email.end_with?('@example.jp')
#
# member.set(
# email: "m-#{member.id}@example.jp",
# site_email: [ member.site_id, member.oauth_type.presence, "m-#{member.id}@example.jp" ].compact.join("_")
# )
# end
# メンバー: 誤って個人情報が漏洩しないように全削除
Cms::Member.all.unscoped.destroy_all
# ジョブのリセット: 誤ってジョブが実行されないようにする
SS::Task.all.unscoped.destroy_all
# ジョブのログ
Job::Log.all.unscoped.destroy_all
Gws::Job::Log.all.unscoped.destroy_all
# 操作履歴
History::Log.all.unscoped.destroy_all
Gws::History.all.unscoped.destroy_all
if Object.const_defined?(:Webmail)
Webmail::History.all.unscoped.destroy_all
end
# メールログ
Sys::MailLog.all.unscoped.destroy_all
# お問い合わせフォームのリセット
Cms::Node.all.unscoped.each do |node|
if node.respond_to?(:notice_email) && node.notice_email.present?
node.set(notice_email: "notice@example.jp")
end
if node.respond_to?(:from_email) && node.from_email.present?
node.set(from_email: "from@example.jp")
end
if node.respond_to?(:kintone_app_api_token) && node.kintone_app_api_token.present?
node.set(kintone_app_api_token: "xxxx")
end
if node.respond_to?(:kintone_app_key) && node.kintone_app_key.present?
node.set(kintone_app_key: "yyyy")
end
end
# お問い合わせの内容
Inquiry::Answer.all.unscoped.destroy_all
# 音声ファイルの削除
Voice::File.all.unscoped.destroy_all
if Cms.const_defined?(:Line)
# LINEのテストメンバー
Cms::Line::TestMember.all.unscoped.destroy_all
# LINEのセッション
Cms::Line::EventSession.all.unscoped.destroy_all
end
#
# 本リセットに加え、メールサーバーを開発用のサーバー(Docker Container)に変更しておくと、
# 誤ってメールが送られることを二重で防ぐことができるので安心です。
#
# `config/mail.yml`(存在しない場合は `config/defaults/mail.yml` を `config/mail.yml` へコピー)を
# テキストエディタで開き、次のように変更します。
#
# ~~~yml
# production: &production
# # smtp or sendmail
# delivery_method: smtp
#
# # smtp settings
# address: localhost
# port: 10587
# domain: example.jp
# user_name: sys@example.jp
# password: pass
# authentication: :cram_md5
# ~~~
#
# 開発用メールサーバーの起動については
# [mail/imap container for shirasagi development](https://github.com/sunny4381/docker-mail) を参照してください。
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment