From 4e07bf00fd209961c600088e4d5efd83b65e9344 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Wed, 10 Mar 2021 02:33:40 +0100 Subject: [PATCH] Add gravatar to profile page. Attempt to make profile look nicer. --- Gemfile | 3 + Gemfile.lock | 2 + app/assets/stylesheets/my_styles.scss | 5 ++ app/models/user.rb | 26 ++++-- app/views/my/logs.slim | 17 ++-- app/views/my/profile.slim | 110 +++++++++++++++++--------- 6 files changed, 116 insertions(+), 47 deletions(-) diff --git a/Gemfile b/Gemfile index f6f0ec3..9db6635 100644 --- a/Gemfile +++ b/Gemfile @@ -146,3 +146,6 @@ gem 'omniauth-rails_csrf_protection' # Role-based access gem 'cancancan' + +# Gravatars +gem 'gravtastic' diff --git a/Gemfile.lock b/Gemfile.lock index cda2623..7085b8e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -131,6 +131,7 @@ GEM sprockets-es6 (>= 0.9.0) globalid (0.4.2) activesupport (>= 4.2.0) + gravtastic (3.2.6) guard (2.16.2) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) @@ -438,6 +439,7 @@ DEPENDENCIES fastimage font-awesome-rails foundation-rails (~> 6.6) + gravtastic guard-minitest guard-rails image_processing diff --git a/app/assets/stylesheets/my_styles.scss b/app/assets/stylesheets/my_styles.scss index 7b3b471..c7777a4 100644 --- a/app/assets/stylesheets/my_styles.scss +++ b/app/assets/stylesheets/my_styles.scss @@ -611,3 +611,8 @@ a.black .label.adminlabel.public { background-color: green !important}; .label.adminlabel.hidden { background-color: blue !important}; .label.adminlabel.unapproved { background-color: orange !important}; + +.gravatar { + border-radius: 50%; + width: 120px; +} \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index e90ce8f..473dc5a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -20,6 +20,9 @@ class User < ApplicationRecord # :github ] + include Gravtastic + gravtastic size: 120 + # Return a human-friendly string describing the user's SSO provider def pretty_provider case self.provider @@ -40,11 +43,24 @@ class User < ApplicationRecord end end - # Check if a user has been created on-the-fly and is just an - # anonymous user who uploaded a screenshot. They can turn this - # user record into a registered account though. - def is_anonymous? - self.provider == nil + def pretty_name + if self.pseudo + 'Anonymous' + elsif self.name? + self.name + else + 'Dr. Who' + end + end + + def pretty_role + if self.pseudo + 'Contributor' + elsif self.moderator_role + 'Moderator' + elsif self.admin_role + 'Admin' + end end def self.from_omniauth(auth) diff --git a/app/views/my/logs.slim b/app/views/my/logs.slim index bf6195b..e5a9a2f 100644 --- a/app/views/my/logs.slim +++ b/app/views/my/logs.slim @@ -1,16 +1,17 @@ = render partial: 'menu' -// Paginator and search bar -.grid-x - .small-6.medium-8.large-9.cell - // Paginator - = render(partial: 'packages/paginator', locals: {items: @logs}) / .small-6.medium-4.large-3.cell / // Search form / = render 'packages/searchfield' - if @logs + // Paginator + .grid-x + .small-6.medium-8.large-9.cell + // Paginator + = render(partial: 'packages/paginator', locals: {items: @logs}) + table thead tr @@ -46,6 +47,12 @@ ' - td #{log.ip_address} + .grid-x + .small-6.medium-8.large-9.cell + // Paginator + = render(partial: 'packages/paginator', locals: {items: @logs}) + + - else p Nothing here. diff --git a/app/views/my/profile.slim b/app/views/my/profile.slim index 477808c..ac1c0b8 100644 --- a/app/views/my/profile.slim +++ b/app/views/my/profile.slim @@ -1,45 +1,81 @@ - = render partial: 'menu' h1 Your data -- unless current_user.name.blank? - h2 Your name - = current_user.name +/ h2 Number of screenshots you uploaded +/ p = current_user.screenshots.count -- unless current_user.email.blank? - h2 Your email address - p = current_user.email - p.help-text - ' This web site recognizes you by your email address. - ' Don't worry - it will not be shown or given to anyone. +- if current_user.provider == 'salsa' + h1 Information for Debian project members + p + | + You are recognized as a member of the Debian project. + Thanks for visiting. Your account has moderation privileges. + That means you can approve screenshots uploaded by visitors. + If screenshots are waiting for moderation you will see a + prominent red bar right at the top. You can also upload your + own screenshots which are going public instantly. + If you stumble upon screenshots that you find offending, + misleading or just useless then feel free to hide them. + Every screenshot will have a status label and action buttons + that are only visible to you. -- unless current_user.provider.blank? - h2 Account provider - p You logged in using #{current_user.pretty_provider}. + p + | + If you have any questions about this web site please contact + Christoph Haas (haas) or Paul Wise (pabs). -h2 Number of screenshots you uploaded -p = current_user.screenshots.count -h2 Your permissions -ul - - if can? :approve, Screenshot.new - li - => fa_icon 'thumbs-up' - 'approve uploaded screenshots - - if can? :destroy, Screenshot.new - li - => fa_icon 'trash' - 'delete screenshots - - if can? :hide, Screenshot.new - li - => fa_icon 'eye-slash' - 'hide screenshots from the public - - if can? :unhide, Screenshot.new - li - => fa_icon 'eye' - 'restore (unhide) screenshots for the public - - if can? :view, Log - li - => fa_icon 'book' - 'view logs +.grid-x + .cell.auto + .cell.small-8.card style="background-color: blue" + + .card + .grid-x.grid-padding-x.grid-padding-y.align-middle + .cell.small-2 + = image_tag current_user.gravatar_url, class: "gravatar" + .cell.small-6 + h3 = current_user.pretty_name + - unless current_user.email.blank? + div + i = current_user.email + - unless current_user.provider.blank? + div Logged in via #{current_user.pretty_provider}. + + .cell + hr + + .card-section + h3 You are + p + = current_user.pretty_role + + .cell + hr + + .card-section + h3 Your permissions + ul + - if can? :approve, Screenshot.new + li + => fa_icon 'thumbs-up' + 'approve uploaded screenshots + - if can? :destroy, Screenshot.new + li + => fa_icon 'trash' + 'delete screenshots + - if can? :hide, Screenshot.new + li + => fa_icon 'eye-slash' + 'hide screenshots from the public + - if can? :unhide, Screenshot.new + li + => fa_icon 'eye' + 'restore (unhide) screenshots for the public + - if can? :view, Log + li + => fa_icon 'book' + 'view logs + + + .cell.auto