From 9dd43238f0ae361a056378b8d354f57460cb5af3 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Thu, 17 Jun 2021 01:12:03 +0800 Subject: [PATCH] Add DefaultAvatar to org. --- controllers/account.go | 2 +- object/organization.go | 13 +++++++------ object/user.go | 4 +++- original/sync.go | 2 ++ web/src/OrganizationEditPage.js | 27 +++++++++++++++++++++++++++ web/src/OrganizationListPage.js | 1 + web/src/locales/en.json | 1 + web/src/locales/zh.json | 1 + 8 files changed, 43 insertions(+), 8 deletions(-) diff --git a/controllers/account.go b/controllers/account.go index d1dc3bca..771c200d 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -141,7 +141,7 @@ func (c *ApiController) Signup() { Type: "normal-user", Password: form.Password, DisplayName: form.Name, - Avatar: "https://casbin.org/img/casbin.svg", + Avatar: organization.DefaultAvatar, Email: form.Email, Phone: form.Phone, Affiliation: form.Affiliation, diff --git a/object/organization.go b/object/organization.go index eb7b45f8..9b099d7d 100644 --- a/object/organization.go +++ b/object/organization.go @@ -24,12 +24,13 @@ type Organization struct { Name string `xorm:"varchar(100) notnull pk" json:"name"` CreatedTime string `xorm:"varchar(100)" json:"createdTime"` - DisplayName string `xorm:"varchar(100)" json:"displayName"` - WebsiteUrl string `xorm:"varchar(100)" json:"websiteUrl"` - Favicon string `xorm:"varchar(100)" json:"favicon"` - PasswordType string `xorm:"varchar(100)" json:"passwordType"` - PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"` - PhonePrefix string `xorm:"varchar(10)" json:"phonePrefix"` + DisplayName string `xorm:"varchar(100)" json:"displayName"` + WebsiteUrl string `xorm:"varchar(100)" json:"websiteUrl"` + Favicon string `xorm:"varchar(100)" json:"favicon"` + PasswordType string `xorm:"varchar(100)" json:"passwordType"` + PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"` + PhonePrefix string `xorm:"varchar(10)" json:"phonePrefix"` + DefaultAvatar string `xorm:"varchar(100)" json:"defaultAvatar"` } func GetOrganizations(owner string) []*Organization { diff --git a/object/user.go b/object/user.go index b9a13af4..34a6fa1b 100644 --- a/object/user.go +++ b/object/user.go @@ -170,7 +170,9 @@ func UpdateUserForOriginal(user *User) bool { } func AddUser(user *User) bool { - user.Id = util.GenerateId() + if user.Id == "" { + user.Id = util.GenerateId() + } organization := GetOrganizationByUser(user) user.UpdateUserPassword(organization) diff --git a/original/sync.go b/original/sync.go index ed77f7ca..6c3dbe89 100644 --- a/original/sync.go +++ b/original/sync.go @@ -58,11 +58,13 @@ func createUserFromOriginalUser(originalUser *User, affiliationMap map[int]strin Avatar: getFullAvatarUrl(originalUser.Avatar), Email: "", Phone: originalUser.Cellphone, + Address: []string{}, Affiliation: affiliation, Score: originalUser.SchoolId, IsAdmin: false, IsGlobalAdmin: false, IsForbidden: originalUser.Deleted != 0, + Properties: map[string]string{}, } return user } diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js index 3265d826..55b22699 100644 --- a/web/src/OrganizationEditPage.js +++ b/web/src/OrganizationEditPage.js @@ -159,6 +159,33 @@ class OrganizationEditPage extends React.Component { }} /> + + + {i18next.t("general:Default avatar")}: + + + + + URL: + + + } value={this.state.organization.defaultAvatar} onChange={e => { + this.updateOrganizationField('defaultAvatar', e.target.value); + }} /> + + + + + {i18next.t("general:Preview")}: + + + + {this.state.organization.defaultAvatar} + + + + + ) } diff --git a/web/src/OrganizationListPage.js b/web/src/OrganizationListPage.js index db1f88fc..55f67d1b 100644 --- a/web/src/OrganizationListPage.js +++ b/web/src/OrganizationListPage.js @@ -53,6 +53,7 @@ class OrganizationListPage extends React.Component { passwordType: "plain", PasswordSalt: "", phonePrefix: "86", + defaultAvatar: "https://casbin.org/img/casbin.svg", } } diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 10b03b4b..ca922898 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -19,6 +19,7 @@ "Display name": "Display name", "Personal name": "Personal name", "Avatar": "Avatar", + "Default avatar": "Default avatar", "URL": "URL", "Preview": "Preview", "User type": "User type", diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index 18e33555..9f53f460 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -19,6 +19,7 @@ "Display name": "显示名称", "Personal name": "姓名", "Avatar": "头像", + "Default avatar": "默认头像", "URL": "链接", "Preview": "预览", "User type": "用户类型",