diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 88eac47b..152f5ff1 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -99,7 +99,7 @@ body { width: auto; } -.unread { +.bg-primary-light { background-color: #e6f3ff; } diff --git a/app/assets/stylesheets/notifications.scss b/app/assets/stylesheets/notifications.scss index 27c3a957..d8daaa78 100644 --- a/app/assets/stylesheets/notifications.scss +++ b/app/assets/stylesheets/notifications.scss @@ -2,21 +2,6 @@ // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ -.unread { - background-color: #e6f3ff; -} - -.big-icon { - font-size: 20px; -} - -.icon-link { - margin-left: 5px; - &:hover { - text-decoration: none; - } -} - .notification-bell { #notification-alert { margin-top: -0.4em; diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index b80552e1..d03d8ae9 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -12,7 +12,7 @@ def index redirect_to '/users/sign_in' if current_user.nil? initialize_vm_categories filter_vm_categories current_user unless current_user.admin? - @notifications = Notification.where(user: current_user).slice(0, number_of_notifications) + @notifications = Notification.where(user: current_user, read: false).slice(0, number_of_notifications) end private diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index c30c2e4e..61648c82 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -1,66 +1,40 @@ # frozen_string_literal: true class NotificationsController < ApplicationController - before_action :set_notification, only: %i[show edit update destroy mark_as_read destroy_and_redirect] + before_action :set_notification, only: %i[destroy mark_as_read mark_as_read_and_redirect] # GET /notifications - # GET /notifications.json def index @notifications = Notification.where(user: current_user) end - # GET /notifications/new - def new - @notification = Notification.new - end - - # POST /notifications - # POST /notifications.json - def create - @notification = Notification.new(notification_params) - @notification.user_id = current_user.id - @notification.read = false - - respond_to do |format| - if @notification.save - format.html { redirect_to notifications_path } - else - format.html { render :new } - end - end - end - # DELETE /notifications/1 - # DELETE /notifications/1.json def destroy - @notification.destroy - respond_to do |format| - format.html { redirect_back fallback_location: notifications_url } - format.json { head :no_content } + if @notification.destroy + notice = "Notification '#{@notification.title}' was successfully deleted." + else + alert = "Error while deleting notification '#{@notification.title}'." end - end - - def destroy_and_redirect - link = @notification.link - @notification.destroy - respond_to do |format| - if link.nil? || link.empty? - format.html { redirect_back fallback_location: notifications_url } - else - format.html { redirect_to link } - end - format.json { head :no_content } + redirect_back fallback_location: notifications_path, notice: notice, alert: alert + end + + # GET /notifications/1/mark_as_read_and_redirect + def mark_as_read_and_redirect + @notification.update(read: true) unless @notification.read + if @notification.link.present? + redirect_to @notification.link + else + redirect_back fallback_location: notifications_path end end - + + # GET /notifications/1/mark_as_read def mark_as_read @notification.read = true - respond_to do |format| - if @notification.save - format.html { redirect_back fallback_location: notifications_path } - else - format.html { redirect_back fallback_location: notifications_path, alert: 'Something went wrong.' } - end + if @notification.save + redirect_back fallback_location: notifications_path + else + redirect_back fallback_location: notifications_path, alert: 'Error while marking notifcation as read.' end end diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index d679c759..2c1955cb 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -146,7 +146,7 @@ def notify_request_update if @request.accepted? ([@request.user] + User.admin).uniq.each do |each| - each.notify('Request has been accepted', @request.description_text, @request.description_url(host_url)) + each.notify('VM request has been accepted', @request.description_text, @request.description_url(host_url)) end @request.users.uniq.each do |each| rights = @request.sudo_users.include?(each) ? 'sudo access' : 'access' @@ -155,7 +155,7 @@ def notify_request_update elsif @request.rejected? message = @request.description_text message += @request.rejection_information.empty? ? '' : "\nwith comment: #{@request.rejection_information}" - notify_users('Request has been rejected', message, @request.description_url(host_url)) + notify_users('VM request has been rejected', message, @request.description_url(host_url)) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index aa3ef400..c4867633 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -30,7 +30,7 @@ def update_role @user.update(role: params[:role]) time = Time.zone.now.strftime('%d/%m/%Y') @user.notify('Changed role', - "Your role has changed from #{former_role} to #{@user.role} on #{time}.", + "Your role has changed from #{former_role} to #{@user.role}.", url_for(controller: :users, action: 'show', id: @user.id)) redirect_to users_path end diff --git a/app/controllers/vms_controller.rb b/app/controllers/vms_controller.rb index f0b57fb5..0bb3101f 100644 --- a/app/controllers/vms_controller.rb +++ b/app/controllers/vms_controller.rb @@ -68,8 +68,8 @@ def request_vm_archivation return if !@vm || @vm.archived? || @vm.pending_archivation? @vm.users.each do |each| - each.notify("Your VM #{@vm.name} has been requested to be archived", - "The VM will soon be archived and for that it will then be shut down.\nIf you still need this VM you can stop the archiving of this VM within #{ArchivationRequest.timeout_readable}.", + each.notify("VM #{@vm.name} archiving requested", + "The VM will soon be archived and it will be shut down.\nIf you still need this VM you can stop the archiving of this VM within #{ArchivationRequest.timeout_readable}.", url_for(controller: :vms, action: 'show', id: @vm.name)) end @vm.set_pending_archivation @@ -84,7 +84,7 @@ def request_vm_revive return if !@vm || @vm.pending_reviving? User.admin.each do |each| - each.notify("VM #{@vm.name} has been requested to be revived", + each.notify("VM #{@vm.name} revival requested", 'The VM has to be revived.', url_for(controller: :vms, action: 'show', id: @vm.name)) end diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 85968f7e..3c3b2314 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -17,13 +17,11 @@
You don't have any notifications at the moment.
+<%= notice %>
-