diff --git a/app/assets/stylesheets/internal.scss b/app/assets/stylesheets/internal.scss new file mode 100644 index 000000000..109374a5e --- /dev/null +++ b/app/assets/stylesheets/internal.scss @@ -0,0 +1,6 @@ +header.internal-edit-header { + display: flex; + h2 { + flex-grow: 1; + } +} diff --git a/app/controllers/internal/organization_memberships_controller.rb b/app/controllers/internal/organization_memberships_controller.rb new file mode 100644 index 000000000..9a5e75428 --- /dev/null +++ b/app/controllers/internal/organization_memberships_controller.rb @@ -0,0 +1,43 @@ +class Internal::OrganizationMembershipsController < Internal::ApplicationController + layout "internal" + + def update + organization_membership = OrganizationMembership.find_by(id: params[:id]) + if organization_membership.update(organization_membership_params) + flash[:success] = "User was successfully updated to #{organization_membership.type_of_user}" + else + flash[:danger] = organization_membership.errors.full_messages + end + redirect_to internal_user_path(organization_membership.user_id) + end + + def create + organization_membership = OrganizationMembership.new(organization_membership_params) + organization = Organization.find_by(id: organization_membership_params[:organization_id]) + if organization && organization_membership.save + flash[:success] = "User was successfully added to #{organization.name}" + elsif organization.blank? + flash[:danger] = "Organization ##{organization_membership_params[:organization_id]} does not exist. Perhaps a typo?" + else + flash[:danger] = organization_membership.errors.full_messages + end + redirect_to internal_user_path(organization_membership.user_id) + end + + def destroy + organization_membership = OrganizationMembership.find_by(id: params[:id]) + if organization_membership.destroy + flash[:success] = "User was successfully removed from org ##{organization_membership.organization_id}" + else + flash[:danger] = "Something wen wrong with removing the user from org ##{organization_membership.organization_id}" + end + redirect_to internal_user_path(organization_membership.user_id) + end + + private + + def organization_membership_params + allowed_params = %i[type_of_user user_title organization_id user_id] + params.require(:organization_membership).permit(allowed_params) + end +end diff --git a/app/controllers/internal/tools_controller.rb b/app/controllers/internal/tools_controller.rb index eaf4c9460..454196ce1 100644 --- a/app/controllers/internal/tools_controller.rb +++ b/app/controllers/internal/tools_controller.rb @@ -4,8 +4,19 @@ class Internal::ToolsController < Internal::ApplicationController def index; end def bust_cache - handle_dead_path if params[:dead_link] - handle_user_cache if params[:bust_user] + flash[:success] = if params[:dead_link] + handle_dead_path + "#{params[:dead_link]} was successfully busted" + elsif params[:bust_user] + handle_user_cache + "User ##{params[:bust_user]} was successfully busted" + elsif params[:bust_article] + handle_article_cache + "Article ##{params[:bust_article]} was successfully busted" + end + redirect_to "/internal/tools" + rescue StandardError => e + flash[:danger] = e redirect_to "/internal/tools" end @@ -22,7 +33,7 @@ class Internal::ToolsController < Internal::ApplicationController end def handle_article_cache - article = User.find(params[:bust_article].to_i) + article = Article.find(params[:bust_article].to_i) article.touch(:last_commented_at) CacheBuster.new.bust_article(article) end diff --git a/app/controllers/internal/users_controller.rb b/app/controllers/internal/users_controller.rb index 55cd27542..6ac61ecbd 100644 --- a/app/controllers/internal/users_controller.rb +++ b/app/controllers/internal/users_controller.rb @@ -37,9 +37,9 @@ class Internal::UsersController < Internal::ApplicationController @user = User.find(params[:id]) begin Moderator::ManageActivityAndRoles.handle_user_roles(admin: current_user, user: @user, user_params: user_params) - flash[:notice] = "User has been udated" + flash[:success] = "User has been updated" rescue StandardError => e - flash[:error] = e.message + flash[:danger] = e.message end redirect_to "/internal/users/#{@user.id}/edit" end @@ -49,7 +49,7 @@ class Internal::UsersController < Internal::ApplicationController begin Moderator::BanishUser.call_banish(admin: current_user, user: @user) rescue StandardError => e - flash[:error] = e.message + flash[:danger] = e.message end redirect_to "/internal/users/#{@user.id}/edit" end @@ -58,9 +58,9 @@ class Internal::UsersController < Internal::ApplicationController @user = User.find(params[:id]) begin Moderator::DeleteUser.call_deletion(admin: current_user, user: @user, user_params: user_params) - flash[:notice] = "@" + @user.username + " (email: " + @user.email + ", user_id: " + @user.id.to_s + ") has been fully deleted. If requested, old content may have been ghostified. If this is a GDPR delete, delete them from Mailchimp & Google Analytics." + flash[:success] = "@" + @user.username + " (email: " + @user.email + ", user_id: " + @user.id.to_s + ") has been fully deleted. If requested, old content may have been ghostified. If this is a GDPR delete, delete them from Mailchimp & Google Analytics." rescue StandardError => e - flash[:error] = e.message + flash[:danger] = e.message end redirect_to "/internal/users" end @@ -70,7 +70,7 @@ class Internal::UsersController < Internal::ApplicationController begin Moderator::MergeUser.call_merge(admin: current_user, keep_user: @user, delete_user_id: user_params["merge_user_id"]) rescue StandardError => e - flash[:error] = e.message + flash[:danger] = e.message end redirect_to "/internal/users/#{@user.id}/edit" end @@ -84,7 +84,7 @@ class Internal::UsersController < Internal::ApplicationController @user.update("#{identity.provider}_username" => nil) flash[:success] = "The #{identity.provider.capitalize} identity was successfully deleted and backed up." rescue StandardError => e - flash[:error] = e.message + flash[:danger] = e.message end redirect_to "/internal/users/#{@user.id}/edit" end @@ -96,7 +96,7 @@ class Internal::UsersController < Internal::ApplicationController identity = backup.recover! flash[:success] = "The #{identity.provider} identity was successfully recovered, and the backup was removed." rescue StandardError => e - flash[:error] = e.message + flash[:danger] = e.message end redirect_to "/internal/users/#{@user.id}/edit" end diff --git a/app/dashboards/sponsorship_dashboard.rb b/app/dashboards/sponsorship_dashboard.rb index bdb039fc3..bf5044d26 100644 --- a/app/dashboards/sponsorship_dashboard.rb +++ b/app/dashboards/sponsorship_dashboard.rb @@ -9,7 +9,9 @@ class SponsorshipDashboard < Administrate::BaseDashboard # on pages throughout the dashboard. ATTRIBUTE_TYPES = { user: Field::BelongsTo, + user_id: UserIdField, organization: Field::BelongsTo, + organization_id: Field::Number, id: Field::Number, level: Field::String, status: Field::String, @@ -63,8 +65,8 @@ class SponsorshipDashboard < Administrate::BaseDashboard # an array of attributes that will be displayed # on the model's form (`new` and `edit`) pages. FORM_ATTRIBUTES = %i[ - user - organization + user_id + organization_id level status expires_at diff --git a/app/models/organization.rb b/app/models/organization.rb index 20a2530b8..9e3c51229 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -4,7 +4,7 @@ class Organization < ApplicationRecord acts_as_followable has_many :job_listings - has_many :organization_memberships + has_many :organization_memberships, dependent: :delete_all has_many :users, through: :organization_memberships has_many :api_secrets, through: :users has_many :articles diff --git a/app/observers/application_observer.rb b/app/observers/application_observer.rb index 001b30f55..4a09b4659 100644 --- a/app/observers/application_observer.rb +++ b/app/observers/application_observer.rb @@ -2,7 +2,7 @@ class ApplicationObserver < ActiveRecord::Observer def warned_user_ping(activity) return unless activity.user.warned == true - SlackBotPingJob.perform_later message: "Activity: https://dev.to/#{activity.path}\nManage @#{activity.user.username}: https://dev.to/internal/users/#{activity.user.id}", + SlackBotPingJob.perform_later message: "Activity: https://dev.to#{activity.path}\nManage @#{activity.user.username}: https://dev.to/internal/users/#{activity.user.id}", channel: "warned-user-comments", username: "sloan_watch_bot", icon_emoji: ":sloan:" diff --git a/app/views/internal/users/_user_organizations.html.erb b/app/views/internal/users/_user_organizations.html.erb new file mode 100644 index 000000000..bfeec453e --- /dev/null +++ b/app/views/internal/users/_user_organizations.html.erb @@ -0,0 +1,38 @@ +
Removing a social account identity can solve certain sign in issues, for example:
<%= identity.provider.capitalize %> UID: <%= identity.uid %> - Username: <%= identity.auth_data_dump["info"]["nickname"] %>
- <%= f.submit "Delete #{identity.provider.capitalize} Identity" %> + <%= f.submit "Delete #{identity.provider.capitalize} Identity", class: "btn btn-danger" %> <% end %> <% end %>