31 Star 294 Fork 112

联犀/things

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
userDeviceShareReadLogic.go 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-10-10 22:13 . feat: 更新mod
package userdevicelogic
import (
"context"
"gitee.com/unitedrhino/core/service/syssvr/pb/sys"
"gitee.com/unitedrhino/share/ctxs"
"gitee.com/unitedrhino/share/errors"
"gitee.com/unitedrhino/things/service/dmsvr/internal/repo/relationDB"
"gitee.com/unitedrhino/things/service/dmsvr/internal/svc"
"gitee.com/unitedrhino/things/service/dmsvr/pb/dm"
"github.com/zeromicro/go-zero/core/logx"
)
type UserDeviceShareReadLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUserDeviceShareReadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserDeviceShareReadLogic {
return &UserDeviceShareReadLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// 获取设备分享的详情
func (l *UserDeviceShareReadLogic) UserDeviceShareRead(in *dm.UserDeviceShareReadReq) (*dm.UserDeviceShareInfo, error) {
uc := ctxs.GetUserCtx(l.ctx)
f := relationDB.UserDeviceShareFilter{
ID: in.Id,
DeviceName: in.Device.GetDeviceName(),
ProductID: in.Device.GetProductID(),
}
if in.Id == 0 { //如果是被分享者来获取
f.SharedUserID = uc.UserID
}
uds, err := relationDB.NewUserDeviceShareRepo(l.ctx).FindOneByFilter(l.ctx, f)
if err != nil {
return nil, err
}
if !uc.IsAdmin && uds.SharedUserID != uc.UserID {
di, err := relationDB.NewDeviceInfoRepo(l.ctx).FindOneByFilter(ctxs.WithAllProject(l.ctx), relationDB.DeviceFilter{ProductID: uds.ProductID, DeviceNames: []string{uds.DeviceName}})
if err != nil {
return nil, err
}
pi, err := l.svcCtx.ProjectM.ProjectInfoRead(l.ctx, &sys.ProjectWithID{ProjectID: int64(di.ProjectID)})
if err != nil {
return nil, err
}
if pi.AdminUserID != uc.UserID { //只有所有者和被分享者才有权限操作
return nil, errors.Permissions
}
}
return ToUserDeviceSharePb(uds), nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/unitedrhino/things.git
git@gitee.com:unitedrhino/things.git
unitedrhino
things
things
v1.0.2

搜索帮助

0d507c66 1850385 C8b1a773 1850385