From 6598d0291cf7dfeb00cb5e5d18faf2bf46fad596 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 25 Jul 2023 10:26:27 +0200 Subject: [PATCH] Allow Organisations to have a E-Mail (#25082) Resolves #25057 This adds a E-Mail field to Organisations. The E-Mail is just shown on the Profile when it is visited by a logged in User. The E-mail is not used for something else. **Screenshots:** ![grafik](https://github.com/go-gitea/gitea/assets/15185051/a8d622b3-7278-4c08-984b-9c5ebfdb5471) ![grafik](https://github.com/go-gitea/gitea/assets/15185051/6dcb1dd7-d04b-49eb-bc96-6582cfe9757b) --------- Co-authored-by: Denys Konovalov Co-authored-by: Denys Konovalov Co-authored-by: wxiaoguang Co-authored-by: Giteabot --- modules/structs/org.go | 3 +++ options/locale/locale_en-US.ini | 1 + routers/api/v1/org/org.go | 12 +++++++++++- routers/web/org/setting.go | 1 + services/convert/convert.go | 1 + services/forms/org.go | 1 + templates/org/home.tmpl | 7 +++++-- templates/org/settings/options.tmpl | 4 ++++ templates/swagger/v1_json.tmpl | 12 ++++++++++++ tests/integration/api_user_orgs_test.go | 4 ++++ web_src/css/org.css | 12 +++++------- 11 files changed, 48 insertions(+), 10 deletions(-) diff --git a/modules/structs/org.go b/modules/structs/org.go index 7c83dcdee7..c0a545ac1c 100644 --- a/modules/structs/org.go +++ b/modules/structs/org.go @@ -8,6 +8,7 @@ type Organization struct { ID int64 `json:"id"` Name string `json:"name"` FullName string `json:"full_name"` + Email string `json:"email"` AvatarURL string `json:"avatar_url"` Description string `json:"description"` Website string `json:"website"` @@ -32,6 +33,7 @@ type CreateOrgOption struct { // required: true UserName string `json:"username" binding:"Required;Username;MaxSize(40)"` FullName string `json:"full_name" binding:"MaxSize(100)"` + Email string `json:"email" binding:"MaxSize(255)"` Description string `json:"description" binding:"MaxSize(255)"` Website string `json:"website" binding:"ValidUrl;MaxSize(255)"` Location string `json:"location" binding:"MaxSize(50)"` @@ -46,6 +48,7 @@ type CreateOrgOption struct { // EditOrgOption options for editing an organization type EditOrgOption struct { FullName string `json:"full_name" binding:"MaxSize(100)"` + Email string `json:"email" binding:"MaxSize(255)"` Description string `json:"description" binding:"MaxSize(255)"` Website string `json:"website" binding:"ValidUrl;MaxSize(255)"` Location string `json:"location" binding:"MaxSize(50)"` diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 8784ab6878..4eb60e5c9b 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2532,6 +2532,7 @@ form.create_org_not_allowed = You are not allowed to create an organization. settings = Settings settings.options = Organization settings.full_name = Full Name +settings.email = Contact Email settings.website = Website settings.location = Location settings.permission = Permissions diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index 4e30ad1762..b0666c87f8 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -255,6 +255,7 @@ func Create(ctx *context.APIContext) { org := &organization.Organization{ Name: form.UserName, FullName: form.FullName, + Email: form.Email, Description: form.Description, Website: form.Website, Location: form.Location, @@ -299,7 +300,15 @@ func Get(ctx *context.APIContext) { ctx.NotFound("HasOrgOrUserVisible", nil) return } - ctx.JSON(http.StatusOK, convert.ToOrganization(ctx, ctx.Org.Organization)) + + org := convert.ToOrganization(ctx, ctx.Org.Organization) + + // Don't show Mail, when User is not logged in + if ctx.Doer == nil { + org.Email = "" + } + + ctx.JSON(http.StatusOK, org) } // Edit change an organization's information @@ -328,6 +337,7 @@ func Edit(ctx *context.APIContext) { form := web.GetForm(ctx).(*api.EditOrgOption) org := ctx.Org.Organization org.FullName = form.FullName + org.Email = form.Email org.Description = form.Description org.Website = form.Website org.Location = form.Location diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go index bd558f78b8..f63b2e9f06 100644 --- a/routers/web/org/setting.go +++ b/routers/web/org/setting.go @@ -100,6 +100,7 @@ func SettingsPost(ctx *context.Context) { } org.FullName = form.FullName + org.Email = form.Email org.Description = form.Description org.Website = form.Website org.Location = form.Location diff --git a/services/convert/convert.go b/services/convert/convert.go index cb246a8b4b..a7a777e8bd 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -289,6 +289,7 @@ func ToOrganization(ctx context.Context, org *organization.Organization) *api.Or Name: org.Name, UserName: org.Name, FullName: org.FullName, + Email: org.Email, Description: org.Description, Website: org.Website, Location: org.Location, diff --git a/services/forms/org.go b/services/forms/org.go index c333bead31..6e2d787516 100644 --- a/services/forms/org.go +++ b/services/forms/org.go @@ -38,6 +38,7 @@ func (f *CreateOrgForm) Validate(req *http.Request, errs binding.Errors) binding type UpdateOrgSettingForm struct { Name string `binding:"Required;Username;MaxSize(40)" locale:"org.org_name_holder"` FullName string `binding:"MaxSize(100)"` + Email string `binding:"MaxSize(255)"` Description string `binding:"MaxSize(255)"` Website string `binding:"ValidUrl;MaxSize(255)"` Location string `binding:"MaxSize(50)"` diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 967b31e7a8..445df520a9 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -15,8 +15,11 @@ {{if $.RenderedDescription}}
{{$.RenderedDescription|Str2html}}
{{end}}
- {{if .Org.Location}}
{{svg "octicon-location"}} {{.Org.Location}}
{{end}} - {{if .Org.Website}}
{{svg "octicon-link"}} {{.Org.Website}}
{{end}} + {{if .Org.Location}}
{{svg "octicon-location"}} {{.Org.Location}}
{{end}} + {{if .Org.Website}}
{{svg "octicon-link"}} {{.Org.Website}}
{{end}} + {{if $.IsSigned}} + {{if .Org.Email}}
{{svg "octicon-mail"}} {{.Org.Email}}
{{end}} + {{end}}
+
+ + +
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 69874bdc75..7cb9bac95d 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -17125,6 +17125,10 @@ "type": "string", "x-go-name": "Description" }, + "email": { + "type": "string", + "x-go-name": "Email" + }, "full_name": { "type": "string", "x-go-name": "FullName" @@ -18043,6 +18047,10 @@ "type": "string", "x-go-name": "Description" }, + "email": { + "type": "string", + "x-go-name": "Email" + }, "full_name": { "type": "string", "x-go-name": "FullName" @@ -20100,6 +20108,10 @@ "type": "string", "x-go-name": "Description" }, + "email": { + "type": "string", + "x-go-name": "Email" + }, "full_name": { "type": "string", "x-go-name": "FullName" diff --git a/tests/integration/api_user_orgs_test.go b/tests/integration/api_user_orgs_test.go index 323facaf48..f76c61f818 100644 --- a/tests/integration/api_user_orgs_test.go +++ b/tests/integration/api_user_orgs_test.go @@ -36,6 +36,7 @@ func TestUserOrgs(t *testing.T) { Name: user17.Name, UserName: user17.Name, FullName: user17.FullName, + Email: user17.Email, AvatarURL: user17.AvatarLink(db.DefaultContext), Description: "", Website: "", @@ -47,6 +48,7 @@ func TestUserOrgs(t *testing.T) { Name: user3.Name, UserName: user3.Name, FullName: user3.FullName, + Email: user3.Email, AvatarURL: user3.AvatarLink(db.DefaultContext), Description: "", Website: "", @@ -106,6 +108,7 @@ func TestMyOrgs(t *testing.T) { Name: user17.Name, UserName: user17.Name, FullName: user17.FullName, + Email: user17.Email, AvatarURL: user17.AvatarLink(db.DefaultContext), Description: "", Website: "", @@ -117,6 +120,7 @@ func TestMyOrgs(t *testing.T) { Name: user3.Name, UserName: user3.Name, FullName: user3.FullName, + Email: user3.Email, AvatarURL: user3.AvatarLink(db.DefaultContext), Description: "", Website: "", diff --git a/web_src/css/org.css b/web_src/css/org.css index d579443ce1..9e1fa38941 100644 --- a/web_src/css/org.css +++ b/web_src/css/org.css @@ -118,13 +118,11 @@ margin-bottom: 10px; } -.organization.profile #org-info .meta .item { - display: inline-block; - margin-right: 10px; -} - -.organization.profile #org-info .meta .item .icon { - margin-right: 5px; +.organization.profile #org-info .meta { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 8px; } .organization.profile .ui.top.header .ui.right {