From d176508010884d034cff7c9f055894c46a9bc03d Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Oct 2021 16:14:45 +0800 Subject: [PATCH 1/9] add: system notification management --- .../admins/system_notifications/index.js | 76 +++++++++++++++++++ .../admins/system_notifications_controller.rb | 76 +++++++++++++++++++ app/models/system_notification.rb | 17 +++++ app/models/system_notification_history.rb | 21 +++++ app/models/user.rb | 4 +- app/views/admins/shared/_sidebar.html.erb | 4 +- .../system_notifications/_form.html.erb | 57 ++++++++++++++ .../system_notifications/_form_modal.html.erb | 40 ++++++++++ .../system_notifications/_list.html.erb | 35 +++++++++ .../admins/system_notifications/edit.js.erb | 2 + .../system_notifications/index.html.erb | 21 +++++ .../admins/system_notifications/index.js.erb | 1 + .../admins/system_notifications/new.js.erb | 2 + config/routes.rb | 5 ++ ...11012060724_create_system_notifications.rb | 13 ++++ ...37_create_system_notification_histories.rb | 10 +++ 16 files changed, 381 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/admins/system_notifications/index.js create mode 100644 app/controllers/admins/system_notifications_controller.rb create mode 100644 app/models/system_notification.rb create mode 100644 app/models/system_notification_history.rb create mode 100644 app/views/admins/system_notifications/_form.html.erb create mode 100644 app/views/admins/system_notifications/_form_modal.html.erb create mode 100644 app/views/admins/system_notifications/_list.html.erb create mode 100644 app/views/admins/system_notifications/edit.js.erb create mode 100644 app/views/admins/system_notifications/index.html.erb create mode 100644 app/views/admins/system_notifications/index.js.erb create mode 100644 app/views/admins/system_notifications/new.js.erb create mode 100644 db/migrate/20211012060724_create_system_notifications.rb create mode 100644 db/migrate/20211012060837_create_system_notification_histories.rb diff --git a/app/assets/javascripts/admins/system_notifications/index.js b/app/assets/javascripts/admins/system_notifications/index.js new file mode 100644 index 000000000..90809b344 --- /dev/null +++ b/app/assets/javascripts/admins/system_notifications/index.js @@ -0,0 +1,76 @@ +/* + * @Description: Do not edit + * @Date: 2021-08-31 11:16:45 + * @LastEditors: viletyy + * @Author: viletyy + * @LastEditTime: 2021-08-31 14:19:46 + * @FilePath: /forgeplus/app/assets/javascripts/admins/system_notifications/index.js + */ +$(document).on('turbolinks:load', function(){ + + var showSuccessNotify = function() { + $.notify({ + message: '操作成功' + },{ + type: 'success' + }); + } + + // close user + $('.system-notification-list-container').on('click', '.close-action', function(){ + var $closeAction = $(this); + var $uncloseAction = $closeAction.siblings('.unclose-action'); + + var keywordID = $closeAction.data('id'); + customConfirm({ + content: '确认取消置顶吗?', + ok: function(){ + $.ajax({ + url: '/admins/system_notifications/' + keywordID, + method: 'PUT', + dataType: 'json', + data: { + system_notification: { + is_top: false + } + }, + success: function() { + showSuccessNotify(); + $closeAction.hide(); + $uncloseAction.show(); + $(".system-notification-item-"+keywordID).children('td').eq(3).text("") + } + }); + } + }); + }); + + // unclose user + $('.system-notification-list-container').on('click', '.unclose-action', function(){ + var $uncloseAction = $(this); + var $closeAction = $uncloseAction.siblings('.close-action'); + + var keywordID = $uncloseAction.data('id'); + customConfirm({ + content: '确认置顶吗?', + ok: function () { + $.ajax({ + url: '/admins/system_notifications/' + keywordID, + method: 'PUT', + dataType: 'json', + data: { + system_notification: { + is_top: true + } + }, + success: function() { + showSuccessNotify(); + $closeAction.show(); + $uncloseAction.hide(); + $(".system-notification-item-"+keywordID).children('td').eq(3).text("√") + } + }); + } + }) + }); +}) \ No newline at end of file diff --git a/app/controllers/admins/system_notifications_controller.rb b/app/controllers/admins/system_notifications_controller.rb new file mode 100644 index 000000000..1a71173c6 --- /dev/null +++ b/app/controllers/admins/system_notifications_controller.rb @@ -0,0 +1,76 @@ +class Admins::SystemNotificationsController < Admins::BaseController + before_action :get_notification, only: [:history, :edit,:update, :destroy] + # before_action :validate_identifer, only: [:create, :update] + + def index + sort_by = SystemNotification.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' + sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc' + q = SystemNotification.ransack(subject_cont: params[:search]) + notifications = q.result(distinct: true).order("#{sort_by} #{sort_direction},created_at desc") + @notifications = paginate(notifications) + end + + def history + @users = @notification.users + end + + def new + @notification = SystemNotification.new + end + + def edit + end + + def create + @notification = SystemNotification.new(notification_params) + if @notification.save + redirect_to admins_system_notifications_path + flash[:success] = '系统保留关键词创建成功' + else + redirect_to admins_system_notifications_path + flash[:danger] = @notification.errors.full_messages.join(",") + end + end + + def update + + respond_to do |format| + if @notification.update_attributes(notification_params) + format.html do + redirect_to admins_system_notifications_path + flash[:success] = '系统保留关键词更新成功' + end + format.js {render_ok} + else + format.html do + redirect_to admins_system_notifications_path + flash[:danger] = @notification.errors.full_messages.join(",") + end + format.js {render_js_error} + end + end + end + + def destroy + if @notification.destroy + redirect_to admins_system_notifications_path + flash[:success] = "系统保留关键词删除成功" + else + redirect_to admins_system_notifications_path + flash[:danger] = "系统保留关键词删除失败" + end + end + + private + def notification_params + params.require(:system_notification).permit! + end + + def get_notification + @notification = SystemNotification.find_by(id: params[:id]) + unless @notification.present? + redirect_to admins_system_notifications_path + flash[:danger] = "系统保留关键词不存在" + end + end +end \ No newline at end of file diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb new file mode 100644 index 000000000..76c514cd3 --- /dev/null +++ b/app/models/system_notification.rb @@ -0,0 +1,17 @@ +# == Schema Information +# +# Table name: system_notifications +# +# id :integer not null, primary key +# subject :string(255) +# sub_subject :string(255) +# content :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# + +class SystemNotification < ApplicationRecord + + has_many :system_notification_histories + has_many :users, through: :system_notification_histories +end diff --git a/app/models/system_notification_history.rb b/app/models/system_notification_history.rb new file mode 100644 index 000000000..8723ca917 --- /dev/null +++ b/app/models/system_notification_history.rb @@ -0,0 +1,21 @@ +# == Schema Information +# +# Table name: system_notification_histories +# +# id :integer not null, primary key +# system_message_id :integer +# user_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_system_notification_histories_on_system_message_id (system_message_id) +# index_system_notification_histories_on_user_id (user_id) +# + +class SystemNotificationHistory < ApplicationRecord + + belongs_to :system_notification + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index 3c4a900a0..22c5e3cd7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -170,7 +170,9 @@ class User < Owner has_many :issues, dependent: :destroy, foreign_key: :author_id has_many :pull_requests, dependent: :destroy has_many :public_keys, class_name: "Gitea::PublicKey",primary_key: :gitea_uid, foreign_key: :owner_id, dependent: :destroy - + has_many :system_notification_histories + has_many :system_notifications, through: :system_notification_histories + # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } scope :like, lambda { |keywords| diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 402449b3b..75abbc124 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -30,8 +30,6 @@
  • <%= sidebar_item(admins_reversed_keywords_path, '系统保留关键词', icon: 'key', controller: 'admins-reversed_keywords') %>
  • -
  • <%= sidebar_item(admins_message_templates_path, '消息模版', icon: 'folder', controller: 'admins-message_templates') %>
  • -
  • <%= sidebar_item(admins_laboratories_path, '云上实验室', icon: 'cloud', controller: 'admins-laboratories') %>
  • @@ -48,6 +46,8 @@ <%= sidebar_item_group('#setting-system', '系统配置', icon: 'wrench') do %>
  • <%= sidebar_item(admins_sites_path, 'setting接口配置', icon: 'deaf', controller: 'admins-sites') %>
  • <%= sidebar_item(admins_edu_settings_path, '全局变量配置', icon: 'pencil-square', controller: 'admins-edu_settings') %>
  • +
  • <%= sidebar_item(admins_system_notifications_path, '系统通知配置', icon: 'bell', controller: 'admins-system_notifications') %>
  • +
  • <%= sidebar_item(admins_message_templates_path, '消息模版配置', icon: 'folder', controller: 'admins-message_templates') %>
  • <% end %>
  • diff --git a/app/views/admins/system_notifications/_form.html.erb b/app/views/admins/system_notifications/_form.html.erb new file mode 100644 index 000000000..8e7619101 --- /dev/null +++ b/app/views/admins/system_notifications/_form.html.erb @@ -0,0 +1,57 @@ +
    +
    <%= type == "create" ? "新建" : "编辑" %>忽略文件
    + <%= link_to "返回", admins_project_ignores_path, class: "btn btn-default pull-right" %> +
    + +
    + <%= form_for @notification, url: {controller: "system_notifications", action: "#{type}"} do |p| %> +
    + +
    + <%= p.text_field :subject, class: "form-control input-lg", placeholder: "请输入系统通知标题" %> +
    + +
    +
    + +
    + <%= p.text_field :sub_subject, class: "form-control input-lg", placeholder: "请输入系统通知副标题" %> +
    + +
    +
    + +
    + <%= p.text_area :content, class:"form-control", style: 'display: none;', rows: "10", cols: "20", placeholer: "请输入系统通知正文" %> +
    + +
    + +
    +
    + <%= p.check_box :is_top, class: "form-check-input", value:"true"%> + +
    +
    +
    + <%= p.submit "确认", class: "btn btn-primary submit-btn" %> +
    + <% end %> +
    \ No newline at end of file diff --git a/app/views/admins/system_notifications/_form_modal.html.erb b/app/views/admins/system_notifications/_form_modal.html.erb new file mode 100644 index 000000000..658bbc9c0 --- /dev/null +++ b/app/views/admins/system_notifications/_form_modal.html.erb @@ -0,0 +1,40 @@ + \ No newline at end of file diff --git a/app/views/admins/system_notifications/_list.html.erb b/app/views/admins/system_notifications/_list.html.erb new file mode 100644 index 000000000..0d86ab035 --- /dev/null +++ b/app/views/admins/system_notifications/_list.html.erb @@ -0,0 +1,35 @@ + + + + + + + + + + + + + <% if notifications.present? %> + <% notifications.each_with_index do |notification, index| %> + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
    序号标题副标题<%= sort_tag('是否置顶', name: 'is_top', path: admins_system_notifications_path) %><%= sort_tag('创建时间', name: 'created_at', path: admins_system_notifications_path) %>操作
    <%= list_index_no((params[:page] || 1).to_i, index) %><%= notification.subject %><%= notification.sub_subject %><%= notification.is_top ? '√' : '' %><%= notification.created_at&.strftime('%Y-%m-%d %H:%M') %> + <%= javascript_void_link '置顶', class: 'action unclose-action', data: { id: notification.id }, style: notification.is_top ? 'display: none;' : '' %> + <%= javascript_void_link '取消置顶', class: 'action close-action', data: { id: notification.id }, style: notification.is_top ? '' : 'display: none;' %> + <%= link_to "编辑", edit_admins_system_notification_path(notification), remote: true, class: "action" %> + <%= link_to "删除", admins_system_notification_path(notification), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %> +
    + +<%= render partial: 'admins/shared/paginate', locals: { objects: notifications } %> \ No newline at end of file diff --git a/app/views/admins/system_notifications/edit.js.erb b/app/views/admins/system_notifications/edit.js.erb new file mode 100644 index 000000000..63fad5838 --- /dev/null +++ b/app/views/admins/system_notifications/edit.js.erb @@ -0,0 +1,2 @@ +$("#admins-system-notification-content").html("<%= j render(partial: 'admins/system_notifications/form', locals: {type: 'create'}) %>") +createMDEditor('system-notification-content-editor', { height: 500, placeholder: '请输入邮件模版' }); \ No newline at end of file diff --git a/app/views/admins/system_notifications/index.html.erb b/app/views/admins/system_notifications/index.html.erb new file mode 100644 index 000000000..01a35f216 --- /dev/null +++ b/app/views/admins/system_notifications/index.html.erb @@ -0,0 +1,21 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('系统通知模版') %> +<% end %> + +
    +
    + <%= form_tag(admins_system_notifications_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %> + <%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '系统通知标题检索') %> + <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> + + <% end %> + <%= link_to "新增", new_admins_system_notification_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %> +
    + +
    +
    + +
    + <%= render partial: 'admins/system_notifications/list', locals: { notifications: @notifications } %> +
    +
    \ No newline at end of file diff --git a/app/views/admins/system_notifications/index.js.erb b/app/views/admins/system_notifications/index.js.erb new file mode 100644 index 000000000..a5cfec841 --- /dev/null +++ b/app/views/admins/system_notifications/index.js.erb @@ -0,0 +1 @@ +$('.system-notification-list-container').html("<%= j( render partial: 'admins/system_notifications/list', locals: { notifications: @notifications } ) %>"); \ No newline at end of file diff --git a/app/views/admins/system_notifications/new.js.erb b/app/views/admins/system_notifications/new.js.erb new file mode 100644 index 000000000..885357b5a --- /dev/null +++ b/app/views/admins/system_notifications/new.js.erb @@ -0,0 +1,2 @@ +$("#admins-system-notification-content").html("<%= j render(partial: 'admins/system_notifications/form', locals: {type: 'create'}) %>") +createMDEditor('system-notification-content-editor', { height: 500, placeholder: '请输入邮件模版' }); diff --git a/config/routes.rb b/config/routes.rb index 005bd926a..b940ed700 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -670,6 +670,11 @@ Rails.application.routes.draw do resources :project_licenses resources :project_ignores resources :reversed_keywords + resources :system_notifications do + member do + get :history + end + end resources :message_templates, only: [:index, :edit, :update] do collection do get :init_data diff --git a/db/migrate/20211012060724_create_system_notifications.rb b/db/migrate/20211012060724_create_system_notifications.rb new file mode 100644 index 000000000..2dcade417 --- /dev/null +++ b/db/migrate/20211012060724_create_system_notifications.rb @@ -0,0 +1,13 @@ +class CreateSystemNotifications < ActiveRecord::Migration[5.2] + def change + # 系统消息 + create_table :system_notifications do |t| + t.string :subject, comment: "标题" + t.string :sub_subject, comment: "副标题" + t.string :content, comment: "正文" + t.boolean :is_top, comment: "是否置顶" + + t.timestamps + end + end +end diff --git a/db/migrate/20211012060837_create_system_notification_histories.rb b/db/migrate/20211012060837_create_system_notification_histories.rb new file mode 100644 index 000000000..9110f3ce9 --- /dev/null +++ b/db/migrate/20211012060837_create_system_notification_histories.rb @@ -0,0 +1,10 @@ +class CreateSystemNotificationHistories < ActiveRecord::Migration[5.2] + def change + create_table :system_notification_histories do |t| + t.references :system_notification + t.references :user + + t.timestamps + end + end +end From 490ce7a2344d6cd4e27aec9b95257409e0823274 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Oct 2021 16:34:00 +0800 Subject: [PATCH 2/9] add: setting of system notification --- .../admins/system_notifications_controller.rb | 12 ++++++------ app/controllers/settings_controller.rb | 6 +++++- app/models/system_notification.rb | 9 +++++++++ app/views/settings/show.json.jbuilder | 9 +++++++++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/controllers/admins/system_notifications_controller.rb b/app/controllers/admins/system_notifications_controller.rb index 1a71173c6..29109fd80 100644 --- a/app/controllers/admins/system_notifications_controller.rb +++ b/app/controllers/admins/system_notifications_controller.rb @@ -6,7 +6,7 @@ class Admins::SystemNotificationsController < Admins::BaseController sort_by = SystemNotification.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc' q = SystemNotification.ransack(subject_cont: params[:search]) - notifications = q.result(distinct: true).order("#{sort_by} #{sort_direction},created_at desc") + notifications = q.result(distinct: true).reorder("#{sort_by} #{sort_direction},created_at desc") @notifications = paginate(notifications) end @@ -25,7 +25,7 @@ class Admins::SystemNotificationsController < Admins::BaseController @notification = SystemNotification.new(notification_params) if @notification.save redirect_to admins_system_notifications_path - flash[:success] = '系统保留关键词创建成功' + flash[:success] = '系统消息创建成功' else redirect_to admins_system_notifications_path flash[:danger] = @notification.errors.full_messages.join(",") @@ -38,7 +38,7 @@ class Admins::SystemNotificationsController < Admins::BaseController if @notification.update_attributes(notification_params) format.html do redirect_to admins_system_notifications_path - flash[:success] = '系统保留关键词更新成功' + flash[:success] = '系统消息更新成功' end format.js {render_ok} else @@ -54,10 +54,10 @@ class Admins::SystemNotificationsController < Admins::BaseController def destroy if @notification.destroy redirect_to admins_system_notifications_path - flash[:success] = "系统保留关键词删除成功" + flash[:success] = "系统消息删除成功" else redirect_to admins_system_notifications_path - flash[:danger] = "系统保留关键词删除失败" + flash[:danger] = "系统消息删除失败" end end @@ -70,7 +70,7 @@ class Admins::SystemNotificationsController < Admins::BaseController @notification = SystemNotification.find_by(id: params[:id]) unless @notification.present? redirect_to admins_system_notifications_path - flash[:danger] = "系统保留关键词不存在" + flash[:danger] = "系统消息不存在" end end end \ No newline at end of file diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index b6662f661..b2dc2e900 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -4,7 +4,7 @@ class SettingsController < ApplicationController get_add_menu get_common_menu get_personal_menu - + get_top_system_notification end private @@ -40,6 +40,10 @@ class SettingsController < ApplicationController end end + def get_top_system_notification + @top_system_notification = SystemNotification.is_top.first + end + def get_site_url(key, value) key.to_s === "url" ? append_http(reset_site_url(value)) : reset_site_url(value) end diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb index 76c514cd3..11220dfc1 100644 --- a/app/models/system_notification.rb +++ b/app/models/system_notification.rb @@ -12,6 +12,15 @@ class SystemNotification < ApplicationRecord + default_scope { order(created_at: :desc)} + has_many :system_notification_histories has_many :users, through: :system_notification_histories + + scope :is_top, lambda { where(is_top: true) } + + + def read_member?(user_id) + self.system_notification_histories.where(user_id: user_id).present? ? true : false + end end diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index 330966aa1..c8d4c89eb 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -56,4 +56,13 @@ json.setting do end json.common @common + + if @top_system_notification.present? + json.system_notification do + json.(@top_system_notification, :subject, :sub_subject, :content) + json.is_read @top_system_notification.read_member?(current_user.id) + end + else + json.system_notification nil + end end From 21af31f23c33c77e2a690a57d8bcf962eb17bc5d Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 13 Oct 2021 10:58:41 +0800 Subject: [PATCH 3/9] add: system notification history api --- ...ystem_notification_histories_controller.rb | 15 +++ app/docs/slate/source/includes/_users.md | 30 +++++ app/models/system_notification_history.rb | 2 + app/views/settings/show.json.jbuilder | 2 +- .../system_notification_histories/zh-CN.yml | 6 + config/routes.rb | 1 + public/docs/api.html | 113 ++++++++++++------ 7 files changed, 129 insertions(+), 40 deletions(-) create mode 100644 app/controllers/users/system_notification_histories_controller.rb create mode 100644 config/locales/system_notification_histories/zh-CN.yml diff --git a/app/controllers/users/system_notification_histories_controller.rb b/app/controllers/users/system_notification_histories_controller.rb new file mode 100644 index 000000000..70e91fbb9 --- /dev/null +++ b/app/controllers/users/system_notification_histories_controller.rb @@ -0,0 +1,15 @@ +class Users::SystemNotificationHistoriesController < Users::BaseController + before_action :private_user_resources!, only: [:create] + def create + @history = observed_user.system_notification_histories.new(system_notification_id: params[:system_notification_id]) + if @history.save + render_ok + else + Rails.logger.info @history.errors.as_json + render_error(@history.errors.full_messages.join(",")) + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + end +end \ No newline at end of file diff --git a/app/docs/slate/source/includes/_users.md b/app/docs/slate/source/includes/_users.md index 9d6b80927..594ce725a 100644 --- a/app/docs/slate/source/includes/_users.md +++ b/app/docs/slate/source/includes/_users.md @@ -199,6 +199,36 @@ await octokit.request('GET /api/users/:login/messages.json') Success Data. +## 用户阅读系统通知 +用户阅读系统通知 + +> 示例: + +```shell +curl -X POST http://localhost:3000/api/users/yystopf/system_notification_histories.json +``` + +```javascript +await octokit.request('GET /api/users/:login/system_notification_histories.json') +``` + +### HTTP 请求 +`POST /api/users/:login/system_notification_histories.json` + +### 请求字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|system_notification_id |integer |阅读的系统通知id | + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "success" +} +``` + ## 发送消息 发送消息, 目前只支持atme diff --git a/app/models/system_notification_history.rb b/app/models/system_notification_history.rb index 8723ca917..b629babdf 100644 --- a/app/models/system_notification_history.rb +++ b/app/models/system_notification_history.rb @@ -18,4 +18,6 @@ class SystemNotificationHistory < ApplicationRecord belongs_to :system_notification belongs_to :user + + validates :system_notification_id, uniqueness: { scope: :user_id, message: '只能阅读一次'} end diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index c8d4c89eb..3b0935e07 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -59,7 +59,7 @@ json.setting do if @top_system_notification.present? json.system_notification do - json.(@top_system_notification, :subject, :sub_subject, :content) + json.(@top_system_notification, :id, :subject, :sub_subject, :content) json.is_read @top_system_notification.read_member?(current_user.id) end else diff --git a/config/locales/system_notification_histories/zh-CN.yml b/config/locales/system_notification_histories/zh-CN.yml new file mode 100644 index 000000000..8dd7b49db --- /dev/null +++ b/config/locales/system_notification_histories/zh-CN.yml @@ -0,0 +1,6 @@ +zh-CN: + activerecord: + attributes: + system_notification_history: + system_notification: "系统通知" + system_notification_id: "系统通知" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b940ed700..92061df93 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -263,6 +263,7 @@ Rails.application.routes.draw do end scope module: :users do + resources :system_notification_histories, only: [:create] resources :applied_messages, only: [:index] resources :applied_transfer_projects, only: [:index] do member do diff --git a/public/docs/api.html b/public/docs/api.html index 8368e8fae..0f1121781 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -348,6 +348,9 @@
  • 用户消息列表
  • +
  • + 用户阅读系统通知 +
  • 发送消息
  • @@ -1328,7 +1331,39 @@ Success — a happy kitten is an authenticated kitten! -

    发送消息

    +

    用户阅读系统通知

    +

    用户阅读系统通知

    + +
    +

    示例:

    +
    +
    curl -X POST http://localhost:3000/api/users/yystopf/system_notification_histories.json
    +
    await octokit.request('GET /api/users/:login/system_notification_histories.json')
    +

    HTTP 请求

    +

    POST /api/users/:login/system_notification_histories.json

    +

    请求字段说明:

    + + + + + + + + + + + + +
    参数类型字段说明
    system_notification_idinteger阅读的系统通知id
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +

    发送消息

    发送消息, 目前只支持atme

    @@ -1336,9 +1371,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/:login/messages.json
     
    await octokit.request('POST /api/users/:login/messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST api/users/yystopf/messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    @@ -1397,9 +1432,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/:login/messages/read.json
     
    await octokit.request('POST /api/users/:login/messages/read.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST api/users/yystopf/messages/read.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1438,9 +1473,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X DELETE http://localhost:3000/api/users/:login/messages.json
     
    await octokit.request('DELETE /api/users/:login/messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    DELETE api/users/yystopf/messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1479,9 +1514,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X PATCH/PUT http://localhost:3000/api/users/yystopf.json
     
    await octokit.request('PATCH/PUT /api/users/:login.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH/PUT /api/users/:login.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1577,7 +1612,7 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/is_pinned_projects.json
     
    await octokit.request('GET /api/users/:login/is_pinned_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/is_pinned_projects.json

    返回字段说明:

    参数
    @@ -1764,9 +1799,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/is_pinned_projects/pin.json
     
    await octokit.request('GET /api/users/:login/is_pinned_projects/pin.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/users/:login/is_pinned_projects/pin.json

    -

    请求字段说明:

    同时设定多个星标项目

    +

    请求字段说明:

    同时设定多个星标项目

    @@ -1810,9 +1845,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X PATCH http://localhost:3000/api/users/yystopf/is_pinned_projects/11.json
     
    await octokit.request('PATCH/PUT /api/users/:login/is_pinned_projects/:id.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH/PUT /api/users/:login/is_pinned_projects/:id.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1851,7 +1886,7 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/activity.json
     
    await octokit.request('GET /api/users/:login/statistics/activity.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/activity.json

    返回字段说明:

    参数
    @@ -1940,9 +1975,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/headmaps.json
     
    await octokit.request('GET /api/users/:login/headmaps.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/headmaps.json

    -

    请求字段说明:

    +

    请求字段说明:

    @@ -2085,9 +2120,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/project_trends.json
     
    await octokit.request('GET /api/users/:login/project_trends.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/project_trends.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2402,9 +2437,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/develop.json
     
    await octokit.request('GET /api/users/:login/statistics/develop.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/develop.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2545,9 +2580,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/role.json
     
    await octokit.request('GET /api/users/:login/statistics/role.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/role.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2627,9 +2662,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/major.json
     
    await octokit.request('GET /api/users/:login/statistics/major.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/major.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2688,9 +2723,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_messages.json
     
    await octokit.request('GET /api/users/:login/applied_messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2967,9 +3002,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_transfer_projects.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3159,9 +3194,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/accept.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects/:id/accept.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects/:id/accept.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3350,9 +3385,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/refuse.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects/:id/refuse.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects/:id/refuse.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3541,9 +3576,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_projects.json
     
    await octokit.request('GET /api/users/:login/applied_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3701,9 +3736,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_projects/2/accept.json
     
    await octokit.request('GET /api/users/:login/applied_projects/:id/accept.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects/:id/accept.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3860,9 +3895,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_projects/2/refuse.json
     
    await octokit.request('GET /api/users/:login/applied_projects/:id/refuse.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects/:id/refuse.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    From 1b87a7a733e0fb27d00b3b561097467ae596f45b Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 13 Oct 2021 15:50:51 +0800 Subject: [PATCH 4/9] fix: send message job need open notice menu --- app/controllers/issues_controller.rb | 26 +++++++++++++------ app/controllers/members_controller.rb | 10 +++---- .../organizations/team_users_controller.rb | 2 +- .../projects/project_units_controller.rb | 2 +- app/controllers/projects_controller.rb | 2 +- app/controllers/pull_requests_controller.rb | 12 ++++----- app/controllers/users/messages_controller.rb | 8 +++--- app/jobs/delay_expired_issue_job.rb | 4 +-- app/models/organization_user.rb | 4 +-- app/models/site.rb | 4 +++ app/models/watcher.rb | 2 +- app/services/projects/accept_join_service.rb | 4 +-- 12 files changed, 47 insertions(+), 33 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index f16edbb38..adbe93e3e 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -111,8 +111,8 @@ class IssuesController < ApplicationController Issues::CreateForm.new({subject:issue_params[:subject]}).validate! @issue = Issue.new(issue_params) if @issue.save! - SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) - SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) if Site.has_notice_menu? if params[:attachment_ids].present? params[:attachment_ids].each do |id| attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) @@ -206,8 +206,8 @@ class IssuesController < ApplicationController Issues::UpdateForm.new({subject:issue_params[:subject]}).validate! if @issue.update_attributes(issue_params) if @issue&.pull_request.present? - SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @issue&.pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value)) - SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @issue&.pull_request&.id ) if @issue.previous_changes[:assigned_to_id].present? + SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @issue&.pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value)) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @issue&.pull_request&.id ) if @issue.previous_changes[:assigned_to_id].present? && Site.has_notice_menu? else previous_changes = @issue.previous_changes.slice(:status_id, :assigned_to_id, :tracker_id, :priority_id, :fixed_version_id, :done_ratio, :issue_tags_value, :branch_name) if @issue.previous_changes[:start_date].present? @@ -216,6 +216,7 @@ class IssuesController < ApplicationController if @issue.previous_changes[:due_date].present? previous_changes.merge!(due_date: [@issue.previous_changes[:due_date][0].to_s, @issue.previous_changes[:due_date][1].to_s]) end +<<<<<<< HEAD if @issue.previous_changes[:status_id].present? && @issue.previous_changes[:status_id][1] == 5 @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) end @@ -224,6 +225,10 @@ class IssuesController < ApplicationController end SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes) SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if @issue.previous_changes[:assigned_to_id].present? +======= + SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if @issue.previous_changes[:assigned_to_id].present? && Site.has_notice_menu? +>>>>>>> 356cafdd (fix: send message job need open notice menu) end if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时 @issue.issue_times.update_all(end_time: Time.now) @@ -276,7 +281,7 @@ class IssuesController < ApplicationController status_id = @issue.status_id token = @issue.token login = @issue.user.try(:login) - SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigned_to_id, @issue.author_id) + SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigned_to_id, @issue.author_id) if Site.has_notice_menu? if @issue.destroy if issue_type == "2" && status_id != 5 post_to_chain("add", token, login) @@ -299,7 +304,7 @@ class IssuesController < ApplicationController issues = Issue.where(id: issue_ids, issue_type: "1") if issues.present? issues.find_each do |i| - SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, i&.subject, i.assigned_to_id, i.author_id) + SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, i&.subject, i.assigned_to_id, i.author_id) if Site.has_notice_menu? end if issues.destroy_all normal_status(0, "删除成功") @@ -344,6 +349,7 @@ class IssuesController < ApplicationController if i.previous_changes[:due_date].present? previous_changes.merge!(due_date: [i.previous_changes[:due_date][0].to_s, i.previous_changes[:due_date][1].to_s]) end +<<<<<<< HEAD if i.previous_changes[:status_id].present? && i.previous_changes[:status_id][1] == 5 i.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) end @@ -352,6 +358,10 @@ class IssuesController < ApplicationController end SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, i&.id, previous_changes) SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, i&.id) if i.previous_changes[:assigned_to_id].present? +======= + SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, i&.id, previous_changes) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, i&.id) if i.previous_changes[:assigned_to_id].present? && Site.has_notice_menu? +>>>>>>> 356cafdd (fix: send message job need open notice menu) end normal_status(0, "批量更新成功") else @@ -366,8 +376,8 @@ class IssuesController < ApplicationController @new_issue = @issue.dup @new_issue.author_id = current_user.id if @new_issue.save - SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @new_issue&.id) - SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @new_issue&.id) + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @new_issue&.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @new_issue&.id) if Site.has_notice_menu? issue_tags = @issue.issue_tags.pluck(:id) if issue_tags.present? issue_tags.each do |tag| diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 0af4898fc..77087770a 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -9,8 +9,8 @@ class MembersController < ApplicationController def create interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user) - SendTemplateMessageJob.perform_later('ProjectJoined', current_user.id, @user.id, @project.id) - SendTemplateMessageJob.perform_later('ProjectMemberJoined', current_user.id, @user.id, @project.id) + SendTemplateMessageJob.perform_later('ProjectJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectMemberJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu? render_response(interactor) rescue Exception => e uid_logger_error(e.message) @@ -30,8 +30,8 @@ class MembersController < ApplicationController def remove interactor = Projects::DeleteMemberInteractor.call(@project.owner, @project, @user) - SendTemplateMessageJob.perform_later('ProjectLeft', current_user.id, @user.id, @project.id) - SendTemplateMessageJob.perform_later('ProjectMemberLeft', current_user.id, @user.id, @project.id) + SendTemplateMessageJob.perform_later('ProjectLeft', current_user.id, @user.id, @project.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectMemberLeft', current_user.id, @user.id, @project.id) if Site.has_notice_menu? render_response(interactor) rescue Exception => e uid_logger_error(e.message) @@ -40,7 +40,7 @@ class MembersController < ApplicationController def change_role interactor = Projects::ChangeMemberRoleInteractor.call(@project.owner, @project, @user, params[:role]) - SendTemplateMessageJob.perform_later('ProjectRole', current_user.id, @user.id, @project.id, message_role_name) + SendTemplateMessageJob.perform_later('ProjectRole', current_user.id, @user.id, @project.id, message_role_name) if Site.has_notice_menu? render_response(interactor) rescue Exception => e uid_logger_error(e.message) diff --git a/app/controllers/organizations/team_users_controller.rb b/app/controllers/organizations/team_users_controller.rb index c63005260..0a5ff28a1 100644 --- a/app/controllers/organizations/team_users_controller.rb +++ b/app/controllers/organizations/team_users_controller.rb @@ -18,7 +18,7 @@ class Organizations::TeamUsersController < Organizations::BaseController ActiveRecord::Base.transaction do @team_user = TeamUser.build(@organization.id, @operate_user.id, @team.id) @organization_user = OrganizationUser.build(@organization.id, @operate_user.id) - SendTemplateMessageJob.perform_later('OrganizationRole', @operate_user.id, @organization.id, @team.authorize_name) + SendTemplateMessageJob.perform_later('OrganizationRole', @operate_user.id, @organization.id, @team.authorize_name) if Site.has_notice_menu? Gitea::Organization::TeamUser::CreateService.call(@organization.gitea_token, @team.gtid, @operate_user.login) end rescue Exception => e diff --git a/app/controllers/projects/project_units_controller.rb b/app/controllers/projects/project_units_controller.rb index e8b8f67a1..52cd857d1 100644 --- a/app/controllers/projects/project_units_controller.rb +++ b/app/controllers/projects/project_units_controller.rb @@ -7,7 +7,7 @@ class Projects::ProjectUnitsController < Projects::BaseController if current_user.admin? || @project.manager?(current_user) ActiveRecord::Base.transaction do before_units, after_units = ProjectUnit.update_by_unit_types!(@project, unit_types) - SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, {navbar: true}) unless before_units.eql?(after_units) + SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, {navbar: true}) unless before_units.eql?(after_units) if Site.has_notice_menu? render_ok end else diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 0dbb666bf..3c5cb1f32 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -145,7 +145,7 @@ class ProjectsController < ApplicationController gitea_repo = Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params) @project.repository.update_attributes({hidden: gitea_repo["private"], identifier: gitea_repo["name"]}) end - SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, @project.previous_changes.slice(:name, :description, :project_category_id, :project_language_id, :is_public)) + SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, @project.previous_changes.slice(:name, :description, :project_category_id, :project_language_id, :is_public)) if Site.has_notice_menu? end rescue Exception => e uid_logger_error(e.message) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index ac3968aad..342f063d2 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -59,8 +59,8 @@ class PullRequestsController < ApplicationController @pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params) if @gitea_pull_request[:status] == :success @pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"]) - SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id) - SendTemplateMessageJob.perform_later('ProjectPullRequest', current_user.id, @pull_request&.id) + SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectPullRequest', current_user.id, @pull_request&.id) if Site.has_notice_menu? else render_error("create pull request error: #{@gitea_pull_request[:status]}") raise ActiveRecord::Rollback @@ -118,8 +118,8 @@ class PullRequestsController < ApplicationController normal_status(-1, e.message) raise ActiveRecord::Rollback end - SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value)) - SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id ) if @issue.previous_changes[:assigned_to_id].present? + SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value)) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id ) if @issue.previous_changes[:assigned_to_id].present? && Site.has_notice_menu? end end @@ -131,7 +131,7 @@ class PullRequestsController < ApplicationController colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user) if colsed === true @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::CLOSE) - SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) + SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) if Site.has_notice_menu? normal_status(1, "已拒绝") else normal_status(-1, '合并失败') @@ -175,7 +175,7 @@ class PullRequestsController < ApplicationController # @pull_request.project_trend_status! @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::MERGE) @issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id) - SendTemplateMessageJob.perform_later('PullRequestMerged', current_user.id, @pull_request.id) + SendTemplateMessageJob.perform_later('PullRequestMerged', current_user.id, @pull_request.id) if Site.has_notice_menu? normal_status(1, "合并成功") else normal_status(-1, result.message) diff --git a/app/controllers/users/messages_controller.rb b/app/controllers/users/messages_controller.rb index 035441ccb..5116f580f 100644 --- a/app/controllers/users/messages_controller.rb +++ b/app/controllers/users/messages_controller.rb @@ -18,16 +18,16 @@ class Users::MessagesController < Users::BaseController Notice::Write::CreateAtmeForm.new(atme_params).validate! case atme_params[:atmeable_type] when 'Issue' - SendTemplateMessageJob.perform_now('IssueAtme', @receivers, current_user.id, atme_params[:atmeable_id]) + SendTemplateMessageJob.perform_now('IssueAtme', @receivers, current_user.id, atme_params[:atmeable_id]) if Site.has_notice_menu? when 'PullRequest' - SendTemplateMessageJob.perform_now('PullRequestAtme', @receivers, current_user.id, atme_params[:atmeable_id]) + SendTemplateMessageJob.perform_now('PullRequestAtme', @receivers, current_user.id, atme_params[:atmeable_id]) if Site.has_notice_menu? when 'Journal' journal = Journal.find_by_id(atme_params[:atmeable_id]) if journal.present? if journal&.issue&.pull_request.present? - SendTemplateMessageJob.perform_now('PullRequestAtme', @receivers, current_user.id, atme_params[:atmeable_id]) + SendTemplateMessageJob.perform_now('PullRequestAtme', @receivers, current_user.id, atme_params[:atmeable_id]) if Site.has_notice_menu? else - SendTemplateMessageJob.perform_now('IssueAtme', @receivers, current_user.id, atme_params[:atmeable_id]) + SendTemplateMessageJob.perform_now('IssueAtme', @receivers, current_user.id, atme_params[:atmeable_id]) if Site.has_notice_menu? end end end diff --git a/app/jobs/delay_expired_issue_job.rb b/app/jobs/delay_expired_issue_job.rb index 4633a953d..bf0e1d2e4 100644 --- a/app/jobs/delay_expired_issue_job.rb +++ b/app/jobs/delay_expired_issue_job.rb @@ -3,8 +3,8 @@ class DelayExpiredIssueJob < ApplicationJob def perform Issue.where(due_date: Date.today + 1.days).find_each do |issue| - SendTemplateMessageJob.perform_later('IssueAssignerExpire', issue.id) - SendTemplateMessageJob.perform_later('IssueCreatorExpire', issue.id) + SendTemplateMessageJob.perform_later('IssueAssignerExpire', issue.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueCreatorExpire', issue.id) if Site.has_notice_menu? end end diff --git a/app/models/organization_user.rb b/app/models/organization_user.rb index 1ad2abd9a..4ff6946b7 100644 --- a/app/models/organization_user.rb +++ b/app/models/organization_user.rb @@ -36,10 +36,10 @@ class OrganizationUser < ApplicationRecord end def send_create_message_to_notice_system - SendTemplateMessageJob.perform_later('OrganizationJoined', self.user_id, self.organization_id) + SendTemplateMessageJob.perform_later('OrganizationJoined', self.user_id, self.organization_id) if Site.has_notice_menu? end def send_destroy_message_to_notice_system - SendTemplateMessageJob.perform_later('OrganizationLeft', self.user_id, self.organization_id) + SendTemplateMessageJob.perform_later('OrganizationLeft', self.user_id, self.organization_id) if Site.has_notice_menu? end end diff --git a/app/models/site.rb b/app/models/site.rb index de352dcc5..af5e78169 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -26,6 +26,10 @@ class Site < ApplicationRecord set_common_menu! end + def self.has_notice_menu? + self.common.where(key: 'notice').present? + end + private def self.set_add_menu! adds= [ diff --git a/app/models/watcher.rb b/app/models/watcher.rb index 7ff20943e..6a8c94fcc 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -37,7 +37,7 @@ class Watcher < ApplicationRecord end def send_create_message_to_notice_system - SendTemplateMessageJob.perform_later('FollowTip', self.id) if self.watchable.is_a?(User) + SendTemplateMessageJob.perform_later('FollowTip', self.id) if self.watchable.is_a?(User) if Site.has_notice_menu? end end diff --git a/app/services/projects/accept_join_service.rb b/app/services/projects/accept_join_service.rb index b1a996fd8..2bbacad69 100644 --- a/app/services/projects/accept_join_service.rb +++ b/app/services/projects/accept_join_service.rb @@ -53,8 +53,8 @@ class Projects::AcceptJoinService < ApplicationService def operate_project_member Projects::AddMemberInteractor.call(@project.owner, @project, @applied_project.user, permission) - SendTemplateMessageJob.perform_later('ProjectJoined', @user.id, @applied_project.user_id, @project.id) - SendTemplateMessageJob.perform_later('ProjectMemberJoined', @user.id, @applied_project.user_id, @project.id) + SendTemplateMessageJob.perform_later('ProjectJoined', @user.id, @applied_project.user_id, @project.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectMemberJoined', @user.id, @applied_project.user_id, @project.id) if Site.has_notice_menu? end def send_apply_message From 0d60e58304d66636a063210442480998a0141c1d Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 13 Oct 2021 17:13:57 +0800 Subject: [PATCH 5/9] fix: system notification edit error --- app/controllers/admins/system_notifications_controller.rb | 1 - app/models/system_notification.rb | 3 ++- app/views/admins/system_notifications/_form.html.erb | 4 ++-- app/views/admins/system_notifications/edit.js.erb | 2 +- ...211013090556_change_system_notification_content_column.rb | 5 +++++ 5 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20211013090556_change_system_notification_content_column.rb diff --git a/app/controllers/admins/system_notifications_controller.rb b/app/controllers/admins/system_notifications_controller.rb index 29109fd80..e2081f1a2 100644 --- a/app/controllers/admins/system_notifications_controller.rb +++ b/app/controllers/admins/system_notifications_controller.rb @@ -33,7 +33,6 @@ class Admins::SystemNotificationsController < Admins::BaseController end def update - respond_to do |format| if @notification.update_attributes(notification_params) format.html do diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb index 11220dfc1..8eacd437c 100644 --- a/app/models/system_notification.rb +++ b/app/models/system_notification.rb @@ -5,7 +5,8 @@ # id :integer not null, primary key # subject :string(255) # sub_subject :string(255) -# content :string(255) +# content :text(65535) +# is_top :boolean # created_at :datetime not null # updated_at :datetime not null # diff --git a/app/views/admins/system_notifications/_form.html.erb b/app/views/admins/system_notifications/_form.html.erb index 8e7619101..33c35747a 100644 --- a/app/views/admins/system_notifications/_form.html.erb +++ b/app/views/admins/system_notifications/_form.html.erb @@ -1,6 +1,6 @@
    -
    <%= type == "create" ? "新建" : "编辑" %>忽略文件
    - <%= link_to "返回", admins_project_ignores_path, class: "btn btn-default pull-right" %> +
    <%= type == "create" ? "新建" : "编辑" %>系统通知
    + <%= link_to "返回", admins_system_notifications_path, class: "btn btn-default pull-right" %>
    diff --git a/app/views/admins/system_notifications/edit.js.erb b/app/views/admins/system_notifications/edit.js.erb index 63fad5838..e5929f876 100644 --- a/app/views/admins/system_notifications/edit.js.erb +++ b/app/views/admins/system_notifications/edit.js.erb @@ -1,2 +1,2 @@ -$("#admins-system-notification-content").html("<%= j render(partial: 'admins/system_notifications/form', locals: {type: 'create'}) %>") +$("#admins-system-notification-content").html("<%= j render(partial: 'admins/system_notifications/form', locals: {type: 'update'}) %>") createMDEditor('system-notification-content-editor', { height: 500, placeholder: '请输入邮件模版' }); \ No newline at end of file diff --git a/db/migrate/20211013090556_change_system_notification_content_column.rb b/db/migrate/20211013090556_change_system_notification_content_column.rb new file mode 100644 index 000000000..1e0e80927 --- /dev/null +++ b/db/migrate/20211013090556_change_system_notification_content_column.rb @@ -0,0 +1,5 @@ +class ChangeSystemNotificationContentColumn < ActiveRecord::Migration[5.2] + def change + change_column :system_notifications, :content, :text + end +end From 1dcc38f6177b7f9553c3b676fe441c36975908b5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Oct 2021 14:54:51 +0800 Subject: [PATCH 6/9] fix: remove system_notification_history --- .../admins/system_notifications_controller.rb | 4 - ...ystem_notification_histories_controller.rb | 15 --- app/docs/slate/source/includes/_users.md | 30 ----- app/models/system_notification.rb | 3 - app/models/system_notification_history.rb | 23 ---- app/models/user.rb | 2 - .../system_notification_histories/zh-CN.yml | 6 - config/routes.rb | 7 +- ...37_create_system_notification_histories.rb | 10 -- public/docs/api.html | 113 ++++++------------ 10 files changed, 40 insertions(+), 173 deletions(-) delete mode 100644 app/controllers/users/system_notification_histories_controller.rb delete mode 100644 app/models/system_notification_history.rb delete mode 100644 config/locales/system_notification_histories/zh-CN.yml delete mode 100644 db/migrate/20211012060837_create_system_notification_histories.rb diff --git a/app/controllers/admins/system_notifications_controller.rb b/app/controllers/admins/system_notifications_controller.rb index e2081f1a2..0dc7dd2a2 100644 --- a/app/controllers/admins/system_notifications_controller.rb +++ b/app/controllers/admins/system_notifications_controller.rb @@ -10,10 +10,6 @@ class Admins::SystemNotificationsController < Admins::BaseController @notifications = paginate(notifications) end - def history - @users = @notification.users - end - def new @notification = SystemNotification.new end diff --git a/app/controllers/users/system_notification_histories_controller.rb b/app/controllers/users/system_notification_histories_controller.rb deleted file mode 100644 index 70e91fbb9..000000000 --- a/app/controllers/users/system_notification_histories_controller.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Users::SystemNotificationHistoriesController < Users::BaseController - before_action :private_user_resources!, only: [:create] - def create - @history = observed_user.system_notification_histories.new(system_notification_id: params[:system_notification_id]) - if @history.save - render_ok - else - Rails.logger.info @history.errors.as_json - render_error(@history.errors.full_messages.join(",")) - end - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - end -end \ No newline at end of file diff --git a/app/docs/slate/source/includes/_users.md b/app/docs/slate/source/includes/_users.md index 594ce725a..9d6b80927 100644 --- a/app/docs/slate/source/includes/_users.md +++ b/app/docs/slate/source/includes/_users.md @@ -199,36 +199,6 @@ await octokit.request('GET /api/users/:login/messages.json') Success Data. -## 用户阅读系统通知 -用户阅读系统通知 - -> 示例: - -```shell -curl -X POST http://localhost:3000/api/users/yystopf/system_notification_histories.json -``` - -```javascript -await octokit.request('GET /api/users/:login/system_notification_histories.json') -``` - -### HTTP 请求 -`POST /api/users/:login/system_notification_histories.json` - -### 请求字段说明: -参数 | 类型 | 字段说明 ---------- | ----------- | ----------- -|system_notification_id |integer |阅读的系统通知id | - -> 返回的JSON示例: - -```json -{ - "status": 0, - "message": "success" -} -``` - ## 发送消息 发送消息, 目前只支持atme diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb index 8eacd437c..848d592d5 100644 --- a/app/models/system_notification.rb +++ b/app/models/system_notification.rb @@ -15,9 +15,6 @@ class SystemNotification < ApplicationRecord default_scope { order(created_at: :desc)} - has_many :system_notification_histories - has_many :users, through: :system_notification_histories - scope :is_top, lambda { where(is_top: true) } diff --git a/app/models/system_notification_history.rb b/app/models/system_notification_history.rb deleted file mode 100644 index b629babdf..000000000 --- a/app/models/system_notification_history.rb +++ /dev/null @@ -1,23 +0,0 @@ -# == Schema Information -# -# Table name: system_notification_histories -# -# id :integer not null, primary key -# system_message_id :integer -# user_id :integer -# created_at :datetime not null -# updated_at :datetime not null -# -# Indexes -# -# index_system_notification_histories_on_system_message_id (system_message_id) -# index_system_notification_histories_on_user_id (user_id) -# - -class SystemNotificationHistory < ApplicationRecord - - belongs_to :system_notification - belongs_to :user - - validates :system_notification_id, uniqueness: { scope: :user_id, message: '只能阅读一次'} -end diff --git a/app/models/user.rb b/app/models/user.rb index 22c5e3cd7..623694b33 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -170,8 +170,6 @@ class User < Owner has_many :issues, dependent: :destroy, foreign_key: :author_id has_many :pull_requests, dependent: :destroy has_many :public_keys, class_name: "Gitea::PublicKey",primary_key: :gitea_uid, foreign_key: :owner_id, dependent: :destroy - has_many :system_notification_histories - has_many :system_notifications, through: :system_notification_histories # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } diff --git a/config/locales/system_notification_histories/zh-CN.yml b/config/locales/system_notification_histories/zh-CN.yml deleted file mode 100644 index 8dd7b49db..000000000 --- a/config/locales/system_notification_histories/zh-CN.yml +++ /dev/null @@ -1,6 +0,0 @@ -zh-CN: - activerecord: - attributes: - system_notification_history: - system_notification: "系统通知" - system_notification_id: "系统通知" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 92061df93..9e5ffa2fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -263,7 +263,6 @@ Rails.application.routes.draw do end scope module: :users do - resources :system_notification_histories, only: [:create] resources :applied_messages, only: [:index] resources :applied_transfer_projects, only: [:index] do member do @@ -671,11 +670,7 @@ Rails.application.routes.draw do resources :project_licenses resources :project_ignores resources :reversed_keywords - resources :system_notifications do - member do - get :history - end - end + resources :system_notifications resources :message_templates, only: [:index, :edit, :update] do collection do get :init_data diff --git a/db/migrate/20211012060837_create_system_notification_histories.rb b/db/migrate/20211012060837_create_system_notification_histories.rb deleted file mode 100644 index 9110f3ce9..000000000 --- a/db/migrate/20211012060837_create_system_notification_histories.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateSystemNotificationHistories < ActiveRecord::Migration[5.2] - def change - create_table :system_notification_histories do |t| - t.references :system_notification - t.references :user - - t.timestamps - end - end -end diff --git a/public/docs/api.html b/public/docs/api.html index 0f1121781..8368e8fae 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -348,9 +348,6 @@
  • 用户消息列表
  • -
  • - 用户阅读系统通知 -
  • 发送消息
  • @@ -1331,39 +1328,7 @@ Success — a happy kitten is an authenticated kitten! -

    用户阅读系统通知

    -

    用户阅读系统通知

    - -
    -

    示例:

    -
    -
    curl -X POST http://localhost:3000/api/users/yystopf/system_notification_histories.json
    -
    await octokit.request('GET /api/users/:login/system_notification_histories.json')
    -

    HTTP 请求

    -

    POST /api/users/:login/system_notification_histories.json

    -

    请求字段说明:

    -
    参数
    - - - - - - - - - - - -
    参数类型字段说明
    system_notification_idinteger阅读的系统通知id
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -    "status": 0,
    -    "message": "success"
    -}
    -

    发送消息

    +

    发送消息

    发送消息, 目前只支持atme

    @@ -1371,9 +1336,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/:login/messages.json
     
    await octokit.request('POST /api/users/:login/messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST api/users/yystopf/messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    @@ -1432,9 +1397,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/:login/messages/read.json
     
    await octokit.request('POST /api/users/:login/messages/read.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST api/users/yystopf/messages/read.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1473,9 +1438,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X DELETE http://localhost:3000/api/users/:login/messages.json
     
    await octokit.request('DELETE /api/users/:login/messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    DELETE api/users/yystopf/messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1514,9 +1479,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X PATCH/PUT http://localhost:3000/api/users/yystopf.json
     
    await octokit.request('PATCH/PUT /api/users/:login.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH/PUT /api/users/:login.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1612,7 +1577,7 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/is_pinned_projects.json
     
    await octokit.request('GET /api/users/:login/is_pinned_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/is_pinned_projects.json

    返回字段说明:

    参数
    @@ -1799,9 +1764,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/is_pinned_projects/pin.json
     
    await octokit.request('GET /api/users/:login/is_pinned_projects/pin.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/users/:login/is_pinned_projects/pin.json

    -

    请求字段说明:

    同时设定多个星标项目

    +

    请求字段说明:

    同时设定多个星标项目

    @@ -1845,9 +1810,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X PATCH http://localhost:3000/api/users/yystopf/is_pinned_projects/11.json
     
    await octokit.request('PATCH/PUT /api/users/:login/is_pinned_projects/:id.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH/PUT /api/users/:login/is_pinned_projects/:id.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1886,7 +1851,7 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/activity.json
     
    await octokit.request('GET /api/users/:login/statistics/activity.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/activity.json

    返回字段说明:

    参数
    @@ -1975,9 +1940,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/headmaps.json
     
    await octokit.request('GET /api/users/:login/headmaps.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/headmaps.json

    -

    请求字段说明:

    +

    请求字段说明:

    @@ -2120,9 +2085,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/project_trends.json
     
    await octokit.request('GET /api/users/:login/project_trends.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/project_trends.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2437,9 +2402,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/develop.json
     
    await octokit.request('GET /api/users/:login/statistics/develop.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/develop.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2580,9 +2545,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/role.json
     
    await octokit.request('GET /api/users/:login/statistics/role.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/role.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2662,9 +2627,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/major.json
     
    await octokit.request('GET /api/users/:login/statistics/major.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/major.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2723,9 +2688,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_messages.json
     
    await octokit.request('GET /api/users/:login/applied_messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3002,9 +2967,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_transfer_projects.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3194,9 +3159,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/accept.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects/:id/accept.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects/:id/accept.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3385,9 +3350,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/refuse.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects/:id/refuse.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects/:id/refuse.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3576,9 +3541,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_projects.json
     
    await octokit.request('GET /api/users/:login/applied_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3736,9 +3701,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_projects/2/accept.json
     
    await octokit.request('GET /api/users/:login/applied_projects/:id/accept.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects/:id/accept.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3895,9 +3860,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_projects/2/refuse.json
     
    await octokit.request('GET /api/users/:login/applied_projects/:id/refuse.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects/:id/refuse.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    From 0885b7d75d4e6c3c4378fe1ee8c08a612d03df66 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Oct 2021 15:02:56 +0800 Subject: [PATCH 7/9] fix --- app/models/system_notification.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb index 848d592d5..6f901b3fd 100644 --- a/app/models/system_notification.rb +++ b/app/models/system_notification.rb @@ -17,8 +17,4 @@ class SystemNotification < ApplicationRecord scope :is_top, lambda { where(is_top: true) } - - def read_member?(user_id) - self.system_notification_histories.where(user_id: user_id).present? ? true : false - end end From 2d4f08316433a73f500ade1a6e745f94ecf64120 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Oct 2021 15:04:16 +0800 Subject: [PATCH 8/9] fix --- app/views/settings/show.json.jbuilder | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index 3b0935e07..1147ffde2 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -60,7 +60,6 @@ json.setting do if @top_system_notification.present? json.system_notification do json.(@top_system_notification, :id, :subject, :sub_subject, :content) - json.is_read @top_system_notification.read_member?(current_user.id) end else json.system_notification nil From ff97daac545e55f1eec46d4349961b9de7097dfe Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Oct 2021 13:52:52 +0800 Subject: [PATCH 9/9] fix --- app/controllers/issues_controller.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index adbe93e3e..446c699e2 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -216,19 +216,14 @@ class IssuesController < ApplicationController if @issue.previous_changes[:due_date].present? previous_changes.merge!(due_date: [@issue.previous_changes[:due_date][0].to_s, @issue.previous_changes[:due_date][1].to_s]) end -<<<<<<< HEAD if @issue.previous_changes[:status_id].present? && @issue.previous_changes[:status_id][1] == 5 @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) end if @issue.previous_changes[:status_id].present? && @issue.previous_changes[:status_id][0] == 5 @issue.project_trends.where(action_type: ProjectTrend::CLOSE).destroy_all end - SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes) - SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if @issue.previous_changes[:assigned_to_id].present? -======= SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes) if Site.has_notice_menu? SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if @issue.previous_changes[:assigned_to_id].present? && Site.has_notice_menu? ->>>>>>> 356cafdd (fix: send message job need open notice menu) end if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时 @issue.issue_times.update_all(end_time: Time.now) @@ -349,19 +344,14 @@ class IssuesController < ApplicationController if i.previous_changes[:due_date].present? previous_changes.merge!(due_date: [i.previous_changes[:due_date][0].to_s, i.previous_changes[:due_date][1].to_s]) end -<<<<<<< HEAD if i.previous_changes[:status_id].present? && i.previous_changes[:status_id][1] == 5 i.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) end if i.previous_changes[:status_id].present? && i.previous_changes[:status_id][0] == 5 i.project_trends.where(action_type: ProjectTrend::CLOSE).destroy_all end - SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, i&.id, previous_changes) - SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, i&.id) if i.previous_changes[:assigned_to_id].present? -======= SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, i&.id, previous_changes) if Site.has_notice_menu? SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, i&.id) if i.previous_changes[:assigned_to_id].present? && Site.has_notice_menu? ->>>>>>> 356cafdd (fix: send message job need open notice menu) end normal_status(0, "批量更新成功") else
    参数