作者 唐旭辉

bug fix

... ... @@ -205,3 +205,13 @@ func ExistRoleName(companyid int64, rname string, types int8) bool {
Exist()
return ok
}
func GetCompanyDefaultRole(companyid int64) (*Role, error) {
r := &Role{}
o := orm.NewOrm()
err := o.QueryTable(&Role{}).
Filter("company_id", companyid).
Filter("is_default", ROLE_DEFAULR).
One(r)
return r, err
}
... ...
... ... @@ -40,7 +40,8 @@ var errmessge ErrorMap = map[string]string{
"10037": "用户的部门必填",
"10038": "用户的角色必填",
"10039": "用户已存在",
// "10040": "注册用户失败",
"10071": "不能删除主管",
"10072": "不能禁用主管",
//部门相关
"10041": "无效的主管设置",
"10042": "上级部门不能选择当前部门及其子部门",
... ...
... ... @@ -178,7 +178,7 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error {
if err != nil {
e := fmt.Errorf("departmentRelationUpdate err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return err
}
return nil
}
... ...
... ... @@ -370,9 +370,16 @@ func validUserCompany(userCompanyid int64, companyid int64) (*models.UserCompany
func UserEdit(param protocol.RequestUserEdit) error {
var (
err error
ucompany *models.UserCompany
err error
ucompany *models.UserCompany
companyInfo *models.Company
)
companyInfo, err = models.GetCompanyById(param.CompanyId)
if err != nil {
log.Error("GetCompanyById(%d):%s", param.CompanyId, err)
return protocol.NewErrWithMessage("1")
}
//校验公司和用户的关联
ucompany, err = validUserCompany(param.UserCompanyID, param.CompanyId)
if err != nil {
... ... @@ -403,27 +410,14 @@ func UserEdit(param protocol.RequestUserEdit) error {
}
o := orm.NewOrm()
o.Begin()
//检查用户手机号是否生变更
// var (
// usrData *models.User
// )
// if usrData.Phone != param.Phone {
// //手机号变更
// uid, err := addNewUser(param.Name, param.Phone, o)
// if err != nil {
// o.Rollback()
// log.Error("手机号变更,新增用户失败;%s", err)
// return protocol.NewErrWithMessage("1")
// }
// ucompany.UserId = uid
// }
//用户数据更新
// err = editUserCompany(param.UserCompanyID, ucompany.UserId, param.Name, o)
// if err != nil {
// o.Rollback()
// log.Error("editUserCompany err:%s", err)
// return protocol.NewErrWithMessage("1")
// }
if ucompany.UserId == companyInfo.AdminId {
defaultRole, err := models.GetCompanyDefaultRole(param.CompanyId)
if err != nil {
log.Error("获取公司默认角色失败")
return protocol.NewErrWithMessage("1")
}
param.Roles = append(param.Roles, defaultRole.Id)
}
//添加角色
err = editUserRole(param.UserCompanyID, ucompany.UserId, param.CompanyId, param.Roles, o)
if err != nil {
... ... @@ -454,9 +448,14 @@ func UserDelete(userCompanyids []int64, companyid int64) error {
return nil
}
var (
updateIds []models.UserCompany
err error
updateIds []models.UserCompany
err error
companyInfo *models.Company
)
companyInfo, err = models.GetCompanyById(companyid)
if err != nil {
log.Error("GetCompanyById(%d)获取公司数据失败:%s", companyid, err)
}
o := orm.NewOrm()
_, err = o.QueryTable(&models.UserCompany{}).
Filter("id__in", userCompanyids).
... ... @@ -466,10 +465,14 @@ func UserDelete(userCompanyids []int64, companyid int64) error {
log.Error("获取用户数据失败:%s", err)
return protocol.NewErrWithMessage("1")
}
var (
ids []int64
)
for _, v := range updateIds {
if v.Id == companyInfo.AdminId {
return protocol.NewErrWithMessage("10071")
}
ids = append(ids, v.Id)
}
_, err = o.QueryTable(&models.UserCompany{}).
... ... @@ -635,9 +638,14 @@ func UserForbid(userCompanyids []int64, companyid int64) error {
return nil
}
var (
updateIds []models.UserCompany
err error
updateIds []models.UserCompany
err error
companyInfo *models.Company
)
companyInfo, err = models.GetCompanyById(companyid)
if err != nil {
log.Error("GetCompanyById(%d) err:%s", companyid, err)
}
o := orm.NewOrm()
_, err = o.QueryTable(&models.UserCompany{}).
Filter("id__in", userCompanyids).
... ... @@ -651,6 +659,9 @@ func UserForbid(userCompanyids []int64, companyid int64) error {
ids []int64
)
for _, v := range updateIds {
if v.Id == companyInfo.AdminId {
return protocol.NewErrWithMessage("10072")
}
ids = append(ids, v.Id)
}
num, err := o.QueryTable(&models.UserCompany{}).
... ...