diff --git a/http/controller/admin/addressBookCollectionRule.go b/http/controller/admin/addressBookCollectionRule.go index e34304b..5a86869 100644 --- a/http/controller/admin/addressBookCollectionRule.go +++ b/http/controller/admin/addressBookCollectionRule.go @@ -120,7 +120,7 @@ func (abcr *AddressBookCollectionRule) CheckForm(t *model.AddressBookCollectionR //check to_id if t.Type == model.ShareAddressBookRuleTypePersonal { if t.ToId == t.UserId { - return "ParamsError", false + return "CannotShareToSelf", false } tou := service.AllService.UserService.InfoById(t.ToId) if tou.Id == 0 { @@ -135,7 +135,7 @@ func (abcr *AddressBookCollectionRule) CheckForm(t *model.AddressBookCollectionR return "ParamsError", false } // 重复检查 - ex := service.AllService.AddressBookService.RulePersonalInfoByToIdAndCid(t.ToId, t.CollectionId) + ex := service.AllService.AddressBookService.RuleInfoByToIdAndCid(t.Type, t.ToId, t.CollectionId) if t.Id == 0 && ex.Id > 0 { return "ItemExists", false } diff --git a/http/controller/admin/my/addressBookCollectionRule.go b/http/controller/admin/my/addressBookCollectionRule.go index c58a5f9..035ec4d 100644 --- a/http/controller/admin/my/addressBookCollectionRule.go +++ b/http/controller/admin/my/addressBookCollectionRule.go @@ -100,21 +100,21 @@ func (abcr *AddressBookCollectionRule) CheckForm(u *model.User, t *model.Address //check to_id if t.Type == model.ShareAddressBookRuleTypePersonal { if t.ToId == t.UserId { - return "ParamsError", false + return "CannotShareToSelf", false } tou := service.AllService.UserService.InfoById(t.ToId) if tou.Id == 0 { return "ItemNotFound", false } //非管理员不能分享给非本组织用户 - if tou.GroupId != u.GroupId { - return "NoAccess", false - } + //if tou.GroupId != u.GroupId { + // return "NoAccess", false + //} } else if t.Type == model.ShareAddressBookRuleTypeGroup { //非管理员不能分享给其他组 - if t.ToId != u.GroupId { - return "NoAccess", false - } + //if t.ToId != u.GroupId { + // return "NoAccess", false + //} tog := service.AllService.GroupService.InfoById(t.ToId) if tog.Id == 0 { @@ -124,7 +124,7 @@ func (abcr *AddressBookCollectionRule) CheckForm(u *model.User, t *model.Address return "ParamsError", false } // 重复检查 - ex := service.AllService.AddressBookService.RulePersonalInfoByToIdAndCid(t.ToId, t.CollectionId) + ex := service.AllService.AddressBookService.RuleInfoByToIdAndCid(t.Type, t.ToId, t.CollectionId) if t.Id == 0 && ex.Id > 0 { return "ItemExists", false } diff --git a/http/controller/admin/user.go b/http/controller/admin/user.go index 4b389d9..e593d02 100644 --- a/http/controller/admin/user.go +++ b/http/controller/admin/user.go @@ -296,32 +296,12 @@ func (ct *User) MyOauth(c *gin.Context) { // groupUsers func (ct *User) GroupUsers(c *gin.Context) { - q := &admin.GroupUsersQuery{} - if err := c.ShouldBindJSON(q); err != nil { - response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) - return - } - u := service.AllService.UserService.CurUser(c) - gid := u.GroupId - uid := u.Id - if service.AllService.UserService.IsAdmin(u) && q.UserId > 0 { - nu := service.AllService.UserService.InfoById(q.UserId) - gid = nu.GroupId - uid = q.UserId - } - res := service.AllService.UserService.List(1, 999, func(tx *gorm.DB) { - tx.Where("group_id = ?", gid) + aG := service.AllService.GroupService.List(1, 999, nil) + aU := service.AllService.UserService.List(1, 9999, nil) + response.Success(c, gin.H{ + "groups": aG.Groups, + "users": aU.Users, }) - var data []*adResp.GroupUsersPayload - for _, _u := range res.Users { - gup := &adResp.GroupUsersPayload{} - gup.FromUser(_u) - if _u.Id == uid { - gup.Status = 0 - } - data = append(data, gup) - } - response.Success(c, data) } // Register diff --git a/http/response/admin/user.go b/http/response/admin/user.go index 8472fda..193e82b 100644 --- a/http/response/admin/user.go +++ b/http/response/admin/user.go @@ -22,15 +22,3 @@ type UserOauthItem struct { Op string `json:"op"` Status int `json:"status"` } - -type GroupUsersPayload struct { - Id uint `json:"id"` - Username string `json:"username"` - Status int `json:"status"` -} - -func (g *GroupUsersPayload) FromUser(user *model.User) { - g.Id = user.Id - g.Username = user.Username - g.Status = 1 -} diff --git a/resources/i18n/en.toml b/resources/i18n/en.toml index bd68267..80c70ba 100644 --- a/resources/i18n/en.toml +++ b/resources/i18n/en.toml @@ -137,4 +137,9 @@ other = "Captcha error." [PwdLoginDisabled] description = "Password login disabled." one = "Password login disabled." -other = "Password login disabled." \ No newline at end of file +other = "Password login disabled." + +[CannotShareToSelf] +description = "Cannot share to self." +one = "Cannot share to self." +other = "Cannot share to self." \ No newline at end of file diff --git a/resources/i18n/es.toml b/resources/i18n/es.toml index f6d1d3d..d795293 100644 --- a/resources/i18n/es.toml +++ b/resources/i18n/es.toml @@ -146,4 +146,9 @@ other = "Error de captcha." [PwdLoginDisabled] description = "Password login disabled." one = "Inicio de sesión con contraseña deshabilitado." -other = "Inicio de sesión con contraseña deshabilitado." \ No newline at end of file +other = "Inicio de sesión con contraseña deshabilitado." + +[CannotShareToSelf] +description = "Cannot share to self." +one = "No se puede compartir con uno mismo." +other = "No se puede compartir con uno mismo." \ No newline at end of file diff --git a/resources/i18n/fr.toml b/resources/i18n/fr.toml index 779eae7..a6805ca 100644 --- a/resources/i18n/fr.toml +++ b/resources/i18n/fr.toml @@ -146,4 +146,9 @@ other = "Erreur de captcha." [PwdLoginDisabled] description = "Password login disabled." one = "Connexion par mot de passe désactivée." -other = "Connexion par mot de passe désactivée." \ No newline at end of file +other = "Connexion par mot de passe désactivée." + +[CannotShareToSelf] +description = "Cannot share to self." +one = "Impossible de partager avec soi-même." +other = "Impossible de partager avec soi-même." \ No newline at end of file diff --git a/resources/i18n/ko.toml b/resources/i18n/ko.toml index ee1b07a..b273aab 100644 --- a/resources/i18n/ko.toml +++ b/resources/i18n/ko.toml @@ -141,3 +141,8 @@ other = "Captcha 오류." description = "Password login disabled." one = "비밀번호 로그인이 비활성화되었습니다." other = "비밀번호 로그인이 비활성화되었습니다." + +[CannotShareToSelf] +description = "Cannot share to self." +one = "자기 자신에게 공유할 수 없습니다." +other = "자기 자신에게 공유할 수 없습니다." \ No newline at end of file diff --git a/resources/i18n/ru.toml b/resources/i18n/ru.toml index fc7c12e..675df26 100644 --- a/resources/i18n/ru.toml +++ b/resources/i18n/ru.toml @@ -146,4 +146,9 @@ other = "Ошибка капчи." [PwdLoginDisabled] description = "Password login disabled." one = "Вход по паролю отключен." -other = "Вход по паролю отключен." \ No newline at end of file +other = "Вход по паролю отключен." + +[CannotShareToSelf] +description = "Cannot share to self." +one = "Нельзя поделиться с собой." +other = "Нельзя поделиться с собой." \ No newline at end of file diff --git a/resources/i18n/zh_CN.toml b/resources/i18n/zh_CN.toml index c37b0c5..030d5c8 100644 --- a/resources/i18n/zh_CN.toml +++ b/resources/i18n/zh_CN.toml @@ -139,4 +139,9 @@ other = "验证码错误。" [PwdLoginDisabled] description = "Password login disabled." one = "密码登录已禁用。" -other = "密码登录已禁用。" \ No newline at end of file +other = "密码登录已禁用。" + +[CannotShareToSelf] +description = "Cannot share to self." +one = "不能共享给自己。" +other = "不能共享给自己。" \ No newline at end of file diff --git a/resources/i18n/zh_TW.toml b/resources/i18n/zh_TW.toml index 5490f78..3660c27 100644 --- a/resources/i18n/zh_TW.toml +++ b/resources/i18n/zh_TW.toml @@ -140,3 +140,8 @@ other = "驗證碼錯誤。" description = "Password login disabled." one = "密碼登錄已禁用。" other = "密碼登錄已禁用。" + +[CannotShareToSelf] +description = "Cannot share to self." +one = "無法共享給自己。" +other = "無法共享給自己。" \ No newline at end of file diff --git a/service/addressBook.go b/service/addressBook.go index dcd01c4..978c792 100644 --- a/service/addressBook.go +++ b/service/addressBook.go @@ -293,8 +293,11 @@ func (s *AddressBookService) RuleInfoById(u uint) *model.AddressBookCollectionRu return p } func (s *AddressBookService) RulePersonalInfoByToIdAndCid(toid, cid uint) *model.AddressBookCollectionRule { + return s.RuleInfoByToIdAndCid(model.ShareAddressBookRuleTypePersonal, toid, cid) +} +func (s *AddressBookService) RuleInfoByToIdAndCid(t int, toid, cid uint) *model.AddressBookCollectionRule { p := &model.AddressBookCollectionRule{} - DB.Where("type = ? and to_id = ? and collection_id = ?", model.ShareAddressBookRuleTypePersonal, toid, cid).First(p) + DB.Where("type = ? and to_id = ? and collection_id = ?", t, toid, cid).First(p) return p } func (s *AddressBookService) CreateRule(t *model.AddressBookCollectionRule) error {