Merge pull request #86 from Retrospring/cleanup

Minor Cleanup
This commit is contained in:
Georg Gadinger 2020-04-26 20:03:46 +02:00 committed by GitHub
commit aeef50ad78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 35 additions and 283 deletions

175
Rakefile
View File

@ -227,66 +227,6 @@ namespace :justask do
puts "#{user.screen_name} is no longer banned."
end
desc "Gives blogger status to an user."
task :blog, [:screen_name] => :environment do |t, args|
fail "screen name required" if args[:screen_name].nil?
user = User.find_by_screen_name(args[:screen_name])
fail "user #{args[:screen_name]} not found" if user.nil?
user.blogger = true
user.save!
puts "#{user.screen_name} is now a blogger."
end
desc "Removes blogger status from an user."
task :unblog, [:screen_name] => :environment do |t, args|
fail "screen name required" if args[:screen_name].nil?
user = User.find_by_screen_name(args[:screen_name])
fail "user #{args[:screen_name]} not found" if user.nil?
user.blogger = false
user.save!
puts "#{user.screen_name} is no longer a blogger."
end
desc "Gives supporter status to an user."
task :sup, [:screen_name] => :environment do |t, args|
fail "screen name required" if args[:screen_name].nil?
user = User.find_by_screen_name(args[:screen_name])
fail "user #{args[:screen_name]} not found" if user.nil?
user.supporter = true
user.save!
puts "#{user.screen_name} is now an supporter."
end
desc "Removes supporter status from an user."
task :desup, [:screen_name] => :environment do |t, args|
fail "screen name required" if args[:screen_name].nil?
user = User.find_by_screen_name(args[:screen_name])
fail "user #{args[:screen_name]} not found" if user.nil?
user.supporter = false
user.save!
puts "#{user.screen_name} is no longer an supporter."
end
desc "Gives contributor status to an user."
task :contrib, [:screen_name] => :environment do |t, args|
fail "screen name required" if args[:screen_name].nil?
user = User.find_by_screen_name(args[:screen_name])
fail "user #{args[:screen_name]} not found" if user.nil?
user.contributor = true
user.save!
puts "#{user.screen_name} is now a contributor."
end
desc "Removes contributor status from an user."
task :decontrib, [:screen_name] => :environment do |t, args|
fail "screen name required" if args[:screen_name].nil?
user = User.find_by_screen_name(args[:screen_name])
fail "user #{args[:screen_name]} not found" if user.nil?
user.contributor = false
user.save!
puts "#{user.screen_name} is no longer a contributor."
end
desc "Lists all users."
task lusers: :environment do
User.all.each do |u|
@ -489,119 +429,4 @@ namespace :justask do
print "\033[0m"
end
end
desc "Export data for an user"
task :export, [:email] => :environment do |t, args|
require 'json'
require 'yaml'
return if args[:email].nil?
obj = {}
format = '%t (%c/%C) [%b>%i] %e'
u = User.where("LOWER(email) = ?", args[:email].downcase).first!
export_dirname = "export_#{u.screen_name}_#{Time.now.to_i}"
export_filename = u.screen_name
%i(id screen_name display_name created_at sign_in_count last_sign_in_at friend_count follower_count asked_count answered_count commented_count smiled_count motivation_header bio website location moderator admin supporter banned blogger).each do |f|
obj[f] = u.send f
end
total = u.questions.count
progress = ProgressBar.create title: 'Processing questions', format: format, starting_at: 0, total: total
obj[:questions] = []
u.questions.each do |q|
qobj = {}
%i(id content author_is_anonymous created_at answer_count).each do |f|
qobj[f] = q.send f
end
obj[:questions] << qobj
progress.increment
end
total = u.answers.count
progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total
obj[:answers] = []
u.answers.each do |a|
aobj = {}
%i(id content comment_count smile_count created_at).each do |f|
aobj[f] = a.send f
end
aobj[:question] = {}
%i(id content author_is_anonymous created_at answer_count).each do |f|
aobj[:question][f] = a.question.send f
end
aobj[:question][:user] = a.question.user.screen_name unless a.question.author_is_anonymous
aobj[:comments] = []
a.comments.each do |c|
cobj = {}
%i(id content created_at).each do |f|
cobj[f] = c.send f
end
cobj[:user] = c.user.screen_name
aobj[:comments] << cobj
end
obj[:answers] << aobj
progress.increment
end
total = u.comments.count
progress = ProgressBar.create title: 'Processing comments', format: format, starting_at: 0, total: total
obj[:comments] = []
u.comments.each do |c|
cobj = {}
%i(id content created_at).each do |f|
cobj[f] = c.send f
end
cobj[:answer] = {}
%i(id content comment_count smile_count created_at).each do |f|
cobj[:answer][f] = c.answer.send f
end
cobj[:answer][:question] = {}
%i(id content author_is_anonymous created_at answer_count).each do |f|
cobj[:answer][:question][f] = c.answer.question.send f
end
cobj[:answer][:question][:user] = c.answer.question.user.screen_name unless c.answer.question.author_is_anonymous
obj[:comments] << cobj
progress.increment
end
total = u.smiles.count
progress = ProgressBar.create title: 'Processing smiles', format: format, starting_at: 0, total: total
obj[:smiles] = []
u.smiles.each do |s|
sobj = {}
%i(id created_at).each do |f|
sobj[f] = s.send f
end
sobj[:answer] = {}
%i(id content comment_count smile_count created_at).each do |f|
sobj[:answer][f] = s.answer.send f
end
sobj[:answer][:question] = {}
%i(id content author_is_anonymous created_at answer_count).each do |f|
sobj[:answer][:question][f] = s.answer.question.send f
end
sobj[:answer][:question][:user] = s.answer.question.user.screen_name unless s.answer.question.author_is_anonymous
obj[:smiles] << sobj
progress.increment
end
`mkdir -p /usr/home/justask/justask/public/export`
`mkdir -p /tmp/rs_export/#{export_dirname}/picture`
if u.profile_picture
%i(large medium small original).each do |s|
x = u.profile_picture.path(s).gsub('"', '\\"')
`cp "#{x}" "/tmp/rs_export/#{export_dirname}/picture/#{s}_#{File.basename x}"`
end
end
File.open "/tmp/rs_export/#{export_dirname}/#{export_filename}.json", 'w' do |f|
f.puts obj.to_json
end
File.open "/tmp/rs_export/#{export_dirname}/#{export_filename}.yml", 'w' do |f|
f.puts obj.to_yaml
end
`tar czvf public/export/#{export_dirname}.tar.gz -C /tmp/rs_export #{export_dirname}`
puts "\033[1mhttps://retrospring.net/export/#{export_dirname}.tar.gz\033[0m"
end
end

View File

@ -164,9 +164,9 @@ class Ajax::ModerationController < ApplicationController
target_user = User.find_by_screen_name(params[:user])
@message = I18n.t('messages.moderation.privilege.nope')
return unless %w(blogger supporter moderator admin contributor translator).include? params[:type].downcase
return unless %w(moderator admin).include? params[:type].downcase
if %w(supporter moderator admin).include?(params[:type].downcase) && !current_user.has_role?(:administrator)
unless current_user.has_role?(:administrator)
@status = :nopriv
@message = I18n.t('messages.moderation.privilege.nopriv')
@success = false
@ -176,21 +176,11 @@ class Ajax::ModerationController < ApplicationController
@checked = status
type = params[:type].downcase
target_role = {"admin" => "administrator"}.fetch(type, type).to_sym
case type
when 'blogger'
target_user.blogger = status
when 'contributor'
target_user.contributor = status
when 'translator'
target_user.translator = status
when 'supporter'
target_user.supporter = status
when 'moderator', 'admin'
if status
target_user.add_role target_role
else
target_user.remove_role target_role
end
if status
target_user.add_role target_role
else
target_user.remove_role target_role
end
target_user.save!

View File

@ -17,7 +17,7 @@ class StaticController < ApplicationController
end
def about
@admins = User.where(admin: true).order(:id)
end
def faq

View File

@ -89,15 +89,6 @@ module ApplicationHelper
((!current_user.nil?) && ((current_user == user) || current_user.mod?)) ? true : false
end
# @deprecated Use {User#profile_picture.url} instead.
def gravatar_url(user)
return user.profile_picture.url :medium
# return '/cage.png'
#return '//www.gravatar.com/avatar' if user.nil?
#return "//www.gravatar.com/avatar/#{Digest::MD5.hexdigest(user)}" if user.is_a? String
#"//www.gravatar.com/avatar/#{Digest::MD5.hexdigest(user.email)}"
end
def ios_web_app?
user_agent = request.env['HTTP_USER_AGENT'] || 'Mozilla/5.0'
# normal MobileSafari.app UA: Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B435 Safari/600.1.4

View File

@ -70,7 +70,6 @@ class User < ApplicationRecord
process_in_background :profile_header
before_save do
self.display_name = 'WRYYYYYYYY' if display_name == 'Dio Brando'
self.website = if website.match %r{\Ahttps?://}
website
else

View File

@ -3,7 +3,7 @@
.media
- unless i.question.author_is_anonymous
%a.pull-left{href: show_user_profile_path(i.question.user.screen_name)}
%img.img-rounded.answerbox--img{src: gravatar_url(i.question.user)}
%img.img-rounded.answerbox--img{src: i.question.user.profile_picture.url(:medium)}
.media-body
%h6.text-muted.media-heading.answerbox--question-user
= raw t('views.inbox.entry.asked', user: user_screen_name(i.question.user, anonymous: i.question.author_is_anonymous), time: time_tooltip(i.question))

View File

@ -6,7 +6,7 @@
%li{data: { comment_id: comment.id }}
.media.comments--media
.pull-left
%img.img-rounded.answerbox--img{src: gravatar_url(comment.user)}
%img.img-rounded.answerbox--img{src: comment.user.profile_picture.url(:medium)}
.media-body.comments--body
%h6.media-heading.answerbox--question-user
= user_screen_name comment.user

View File

@ -1,7 +1,7 @@
- unless report.nil? or report.target.nil? or report.user.nil? or report.type.nil?
.panel.panel-default.moderationbox{data: { id: report.id }}
.panel-heading
%img.img-rounded.answerbox--img{src: gravatar_url(report.user)}
%img.img-rounded.answerbox--img{src: report.user.profile_picture.url(:medium)}
= raw t('views.moderation.moderationbox.reported', user: user_screen_name(report.user), content: report.type.sub('Reports::', ''), time: time_tooltip(report))
.panel-body
%p

View File

@ -4,7 +4,7 @@
.media.question-media
- unless a.question.author_is_anonymous
%a.pull-left{href: show_user_profile_path(a.question.user.screen_name)}
%img.img-rounded.answerbox--img{src: gravatar_url(a.question.user)}
%img.img-rounded.answerbox--img{src: a.question.user.profile_picture.url(:medium)}
.media-body.question-body
- if user_signed_in?
.pull-right
@ -49,7 +49,7 @@
.media
.pull-left
%a{href: show_user_profile_path(a.user.screen_name)}
%img.img-rounded.answerbox--img{src: gravatar_url(a.user)}
%img.img-rounded.answerbox--img{src: a.user.profile_picture.url(:medium)}
.media-body
%h6.media-heading.answerbox--answer-user
= raw t('views.answerbox.answered', hide: hidespan(t('views.answerbox.hide'), "xs"), user: user_screen_name(a.user))

View File

@ -14,5 +14,5 @@
- comment.smiles.all.each do |smile|
%li.user-list-entry.user-list-entry-smiles
%a{href: show_user_profile_path(smile.user.screen_name)}
%img.img-rounded{src: gravatar_url(smile.user), alt: user_screen_name(smile.user, url: false)}
%img.img-rounded{src: smile.user.profile_picture.url(:medium), alt: user_screen_name(smile.user, url: false)}
%span= user_screen_name(smile.user, url: false)

View File

@ -7,7 +7,7 @@
%div{class: "ab-comment-smile-list", style: "height: 0; width: 0"}= render "shared/comment_smiles", comment: comment
.media.comments--media
.pull-left
%img.img-rounded.answerbox--img{src: gravatar_url(comment.user)}
%img.img-rounded.answerbox--img{src: comment.user.profile_picture.url(:medium)}
.media-body.comments--body
%h6.media-heading.answerbox--question-user
= user_screen_name comment.user

View File

@ -4,7 +4,7 @@
.media.question-media
- unless question.author_is_anonymous
%a.pull-left{href: unless hidden then show_user_profile_path(question.user.screen_name) end}
%img.img-rounded.answerbox--img{src: gravatar_url(question.user)}
%img.img-rounded.answerbox--img{src: question.user.profile_picture.url(:medium)}
.media-body.question-body
- if user_signed_in?
.pull-right

View File

@ -7,4 +7,4 @@
- else
- a.smiles.all.each do |smile|
%a{href: show_user_profile_path(smile.user.screen_name), title: smile.user.screen_name, data: { toggle: :tooltip, placement: :top, smile_id: smile.id }}
%img.img-rounded.answerbox--img-small{src: gravatar_url(smile.user)}
%img.img-rounded.answerbox--img-small{src: smile.user.profile_picture.url(:medium)}

View File

@ -37,14 +37,6 @@
%h4.heading-about.text-center= t 'views.about.repository.title'
%p.text-center
%em= t 'views.about.repository.desc'
.col-md-4
%h3= t 'views.about.contributors.title'
%p= t('views.about.contributors.desc', app_title: APP_CONFIG['site_name'])
%p= raw t('views.about.contributors.howto', fork: link_to(t('views.about.contributors.fork'), "https://github.com/retrospring/retrospring"))
%ul.about--moderator
- User.where(contributor: true).each do |sup|
%a{href: show_user_profile_path(sup.screen_name), title: sup.screen_name, data: { toggle: :tooltip, placement: :top }}
%img.img-rounded.answerbox--img-small{src: sup.profile_picture.url(:medium)}
.panel.panel-default
.panel-body
.row
@ -57,9 +49,9 @@
%h2.entry-text#answered-count= Answer.count
%h4.entry-subtext= t('views.general.answer').pluralize(Answer.count)
.col-md-3.col-sm-6.col-xs-6.statistics
%h2.entry-text#asked-count= Comment.count
%h2.entry-text#comment-count= Comment.count
%h4.entry-subtext= t('views.general.comment').pluralize(Comment.count)
%h2.entry-text#answered-count= Smile.count + CommentSmile.count
%h2.entry-text#smile-count= Smile.count + CommentSmile.count
%h4.entry-subtext= t('views.general.smile').pluralize(Smile.count)
.col-md-3.col-sm-12.col-xs-12.users
.entry-text#follower-count= User.count

View File

@ -8,11 +8,7 @@
%h4#modal-privileges-label.modal-title
= raw t('views.actions.privilege', user: @user.screen_name)
%ul.list-group.groups--list
= render 'user/modal_privileges_item', privilege: 'blogger', description: t('views.modal.privilege.blogger'), user: @user
= render 'user/modal_privileges_item', privilege: 'contributor', description: t('views.modal.privilege.contributor'), user: @user
= render 'user/modal_privileges_item', privilege: 'translator', description: t('views.modal.privilege.translator'), user: @user
- if current_user.has_role?(:administrator)
= render 'user/modal_privileges_item', privilege: 'supporter', description: t('views.modal.privilege.supporter'), user: @user
= render 'user/modal_privileges_item', privilege: 'moderator', description: t('views.modal.privilege.moderator'),user: @user
= render 'user/modal_privileges_item', privilege: 'admin', description: t('views.modal.privilege.admin'), user: @user
.modal-footer

View File

@ -111,41 +111,6 @@
%span.label.label-danger
%i.fa.fa-fw.fa-close
%p.data-heading Supporter
%p
- if current_user.supporter?
%span.label.label-success
%i.fa.fa-fw.fa-check
- else
%span.label.label-danger
%i.fa.fa-fw.fa-close
%p.data-heading Contributor
%p
- if current_user.contributor?
%span.label.label-success
%i.fa.fa-fw.fa-check
- else
%span.label.label-danger
%i.fa.fa-fw.fa-close
%p.data-heading Blogger
%p
- if current_user.blogger?
%span.label.label-success
%i.fa.fa-fw.fa-check
- else
%span.label.label-danger
%i.fa.fa-fw.fa-close
%p.data-heading Translator
%p
- if current_user.translator?
%span.label.label-success
%i.fa.fa-fw.fa-check
- else
%span.label.label-danger
%i.fa.fa-fw.fa-close
.row
.col-md-6.col-sm-6.col-xs-12
%h3 IP

View File

@ -438,19 +438,11 @@ en:
name: "Group name"
members: "members"
privilege:
blogger: "The user gets that privilege if they blogged something (nice) about Retrospring."
contributor: "This user has contributed to justask (the software behind Retrospring)."
supporter: "This user monetarily supports the site."
moderator: "Someone trustworthy enough to help managing reports."
admin: "This user is part of the core team."
translator: "This user helped translating Retrospring into their language."
user:
follows_you: "Follows you"
title:
admin: "Admin"
moderator: "Moderator"
supporter: "Supporter"
contributor: "Contributor"
blogger: "Blogger"
banned: "Banned"
translator: "Translator"

View File

@ -0,0 +1,10 @@
class RemoveUnusedProfileFlags < ActiveRecord::Migration[5.2]
def change
remove_column :users, :admin
remove_column :users, :blogger
remove_column :users, :contributor
remove_column :users, :moderator
remove_column :users, :supporter
remove_column :users, :translator
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_04_19_185535) do
ActiveRecord::Schema.define(version: 2020_04_25_194536) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -241,12 +241,10 @@ ActiveRecord::Schema.define(version: 2020_04_19_185535) do
t.integer "commented_count", default: 0, null: false
t.string "display_name"
t.integer "smiled_count", default: 0, null: false
t.boolean "admin", default: false, null: false
t.string "motivation_header", default: "", null: false
t.string "website", default: "", null: false
t.string "location", default: "", null: false
t.text "bio", default: "", null: false
t.boolean "moderator", default: false, null: false
t.string "profile_picture_file_name"
t.string "profile_picture_content_type"
t.integer "profile_picture_file_size"
@ -256,14 +254,11 @@ ActiveRecord::Schema.define(version: 2020_04_19_185535) do
t.integer "crop_y"
t.integer "crop_w"
t.integer "crop_h"
t.boolean "supporter", default: false
t.boolean "privacy_allow_anonymous_questions", default: true
t.boolean "privacy_allow_public_timeline", default: true
t.boolean "privacy_allow_stranger_answers", default: true
t.boolean "privacy_show_in_search", default: true
t.boolean "permanently_banned", default: false
t.boolean "blogger", default: false
t.boolean "contributor", default: false
t.string "ban_reason"
t.datetime "banned_until"
t.integer "comment_smiled_count", default: 0, null: false
@ -277,7 +272,6 @@ ActiveRecord::Schema.define(version: 2020_04_19_185535) do
t.integer "crop_h_w"
t.integer "crop_h_h"
t.string "locale", default: "en"
t.boolean "translator", default: false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"

View File

@ -34,15 +34,14 @@ class Exporter
private
def collect_user_info
%i(answered_count asked_count ban_reason banned_until bio blogger comment_smiled_count commented_count
confirmation_sent_at confirmed_at contributor created_at crop_h crop_h_h crop_h_w crop_h_x crop_h_y
%i(answered_count asked_count ban_reason banned_until bio comment_smiled_count commented_count
confirmation_sent_at confirmed_at created_at crop_h crop_h_h crop_h_w crop_h_x crop_h_y
crop_w crop_x crop_y current_sign_in_at current_sign_in_ip display_name email follower_count friend_count
id last_sign_in_at last_sign_in_ip locale location motivation_header permanently_banned
privacy_allow_anonymous_questions privacy_allow_public_timeline privacy_allow_stranger_answers
privacy_show_in_search profile_header_content_type profile_header_file_name profile_header_file_size
profile_header_updated_at profile_picture_content_type profile_picture_file_name profile_picture_file_size
profile_picture_updated_at screen_name show_foreign_themes sign_in_count smiled_count supporter translator
updated_at website).each do |f|
profile_picture_updated_at screen_name show_foreign_themes sign_in_count smiled_count updated_at website).each do |f|
@obj[f] = @user.send f
end
@ -229,9 +228,8 @@ class Exporter
def user_stub(user)
uobj = {}
%i(answered_count asked_count bio blogger comment_smiled_count commented_count contributor created_at
display_name follower_count friend_count id location motivation_header permanently_banned screen_name
smiled_count supporter translator website).each do |f|
%i(answered_count asked_count bio comment_smiled_count commented_count created_at display_name follower_count
friend_count id location motivation_header permanently_banned screen_name smiled_count website).each do |f|
uobj[f] = user.send f
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 566 KiB

After

Width:  |  Height:  |  Size: 546 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 337 B

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 886 B

After

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB