mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 12:45:46 +08:00
FIX revert system_notification_histories
This commit is contained in:
@@ -10,6 +10,10 @@ class Admins::SystemNotificationsController < Admins::BaseController
|
||||
@notifications = paginate(notifications)
|
||||
end
|
||||
|
||||
def history
|
||||
@users = @notification.users
|
||||
end
|
||||
|
||||
def new
|
||||
@notification = SystemNotification.new
|
||||
end
|
||||
|
||||
@@ -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
|
||||
@@ -199,6 +199,36 @@ await octokit.request('GET /api/users/:login/messages.json')
|
||||
Success Data.
|
||||
</aside>
|
||||
|
||||
## 用户阅读系统通知
|
||||
用户阅读系统通知
|
||||
|
||||
> 示例:
|
||||
|
||||
```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
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ 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)
|
||||
|
||||
23
app/models/system_notification_history.rb
Normal file
23
app/models/system_notification_history.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
# == 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
|
||||
@@ -173,6 +173,9 @@ class User < Owner
|
||||
|
||||
has_one :user_template_message_setting, 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|
|
||||
|
||||
Reference in New Issue
Block a user