Skip to content

Commit 6598d02

Browse files
JakobDevdenyskonwxiaoguangGiteaBot
authored
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 <[email protected]> Co-authored-by: Denys Konovalov <[email protected]> Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent af1ffbc commit 6598d02

File tree

11 files changed

+48
-10
lines changed

11 files changed

+48
-10
lines changed

modules/structs/org.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type Organization struct {
88
ID int64 `json:"id"`
99
Name string `json:"name"`
1010
FullName string `json:"full_name"`
11+
Email string `json:"email"`
1112
AvatarURL string `json:"avatar_url"`
1213
Description string `json:"description"`
1314
Website string `json:"website"`
@@ -32,6 +33,7 @@ type CreateOrgOption struct {
3233
// required: true
3334
UserName string `json:"username" binding:"Required;Username;MaxSize(40)"`
3435
FullName string `json:"full_name" binding:"MaxSize(100)"`
36+
Email string `json:"email" binding:"MaxSize(255)"`
3537
Description string `json:"description" binding:"MaxSize(255)"`
3638
Website string `json:"website" binding:"ValidUrl;MaxSize(255)"`
3739
Location string `json:"location" binding:"MaxSize(50)"`
@@ -46,6 +48,7 @@ type CreateOrgOption struct {
4648
// EditOrgOption options for editing an organization
4749
type EditOrgOption struct {
4850
FullName string `json:"full_name" binding:"MaxSize(100)"`
51+
Email string `json:"email" binding:"MaxSize(255)"`
4952
Description string `json:"description" binding:"MaxSize(255)"`
5053
Website string `json:"website" binding:"ValidUrl;MaxSize(255)"`
5154
Location string `json:"location" binding:"MaxSize(50)"`

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,7 @@ form.create_org_not_allowed = You are not allowed to create an organization.
25322532
settings = Settings
25332533
settings.options = Organization
25342534
settings.full_name = Full Name
2535+
settings.email = Contact Email
25352536
settings.website = Website
25362537
settings.location = Location
25372538
settings.permission = Permissions

routers/api/v1/org/org.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ func Create(ctx *context.APIContext) {
255255
org := &organization.Organization{
256256
Name: form.UserName,
257257
FullName: form.FullName,
258+
Email: form.Email,
258259
Description: form.Description,
259260
Website: form.Website,
260261
Location: form.Location,
@@ -299,7 +300,15 @@ func Get(ctx *context.APIContext) {
299300
ctx.NotFound("HasOrgOrUserVisible", nil)
300301
return
301302
}
302-
ctx.JSON(http.StatusOK, convert.ToOrganization(ctx, ctx.Org.Organization))
303+
304+
org := convert.ToOrganization(ctx, ctx.Org.Organization)
305+
306+
// Don't show Mail, when User is not logged in
307+
if ctx.Doer == nil {
308+
org.Email = ""
309+
}
310+
311+
ctx.JSON(http.StatusOK, org)
303312
}
304313

305314
// Edit change an organization's information
@@ -328,6 +337,7 @@ func Edit(ctx *context.APIContext) {
328337
form := web.GetForm(ctx).(*api.EditOrgOption)
329338
org := ctx.Org.Organization
330339
org.FullName = form.FullName
340+
org.Email = form.Email
331341
org.Description = form.Description
332342
org.Website = form.Website
333343
org.Location = form.Location

routers/web/org/setting.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func SettingsPost(ctx *context.Context) {
100100
}
101101

102102
org.FullName = form.FullName
103+
org.Email = form.Email
103104
org.Description = form.Description
104105
org.Website = form.Website
105106
org.Location = form.Location

services/convert/convert.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ func ToOrganization(ctx context.Context, org *organization.Organization) *api.Or
289289
Name: org.Name,
290290
UserName: org.Name,
291291
FullName: org.FullName,
292+
Email: org.Email,
292293
Description: org.Description,
293294
Website: org.Website,
294295
Location: org.Location,

services/forms/org.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (f *CreateOrgForm) Validate(req *http.Request, errs binding.Errors) binding
3838
type UpdateOrgSettingForm struct {
3939
Name string `binding:"Required;Username;MaxSize(40)" locale:"org.org_name_holder"`
4040
FullName string `binding:"MaxSize(100)"`
41+
Email string `binding:"MaxSize(255)"`
4142
Description string `binding:"MaxSize(255)"`
4243
Website string `binding:"ValidUrl;MaxSize(255)"`
4344
Location string `binding:"MaxSize(50)"`

templates/org/home.tmpl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
</div>
1616
{{if $.RenderedDescription}}<div class="render-content markup">{{$.RenderedDescription|Str2html}}</div>{{end}}
1717
<div class="text grey meta">
18-
{{if .Org.Location}}<div class="item">{{svg "octicon-location"}} <span>{{.Org.Location}}</span></div>{{end}}
19-
{{if .Org.Website}}<div class="item">{{svg "octicon-link"}} <a target="_blank" rel="noopener noreferrer me" href="{{.Org.Website}}">{{.Org.Website}}</a></div>{{end}}
18+
{{if .Org.Location}}<div class="flex-text-block">{{svg "octicon-location"}} <span>{{.Org.Location}}</span></div>{{end}}
19+
{{if .Org.Website}}<div class="flex-text-block">{{svg "octicon-link"}} <a target="_blank" rel="noopener noreferrer me" href="{{.Org.Website}}">{{.Org.Website}}</a></div>{{end}}
20+
{{if $.IsSigned}}
21+
{{if .Org.Email}}<div class="flex-text-block">{{svg "octicon-mail"}} <a class="muted" href="mailto:{{.Org.Email}}">{{.Org.Email}}</a></div>{{end}}
22+
{{end}}
2023
</div>
2124
</div>
2225
<div class="right menu">

templates/org/settings/options.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<label for="full_name">{{.locale.Tr "org.org_full_name_holder"}}</label>
1919
<input id="full_name" name="full_name" value="{{.Org.FullName}}" maxlength="100">
2020
</div>
21+
<div class="field {{if .Err_Email}}error{{end}}">
22+
<label for="email">{{.locale.Tr "org.settings.email"}}</label>
23+
<input id="email" name="email" type="email" value="{{.Org.Email}}" maxlength="255">
24+
</div>
2125
<div class="field {{if .Err_Description}}error{{end}}">
2226
<label for="description">{{$.locale.Tr "org.org_desc"}}</label>
2327
<textarea id="description" name="description" rows="2" maxlength="255">{{.Org.Description}}</textarea>

templates/swagger/v1_json.tmpl

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/api_user_orgs_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestUserOrgs(t *testing.T) {
3636
Name: user17.Name,
3737
UserName: user17.Name,
3838
FullName: user17.FullName,
39+
Email: user17.Email,
3940
AvatarURL: user17.AvatarLink(db.DefaultContext),
4041
Description: "",
4142
Website: "",
@@ -47,6 +48,7 @@ func TestUserOrgs(t *testing.T) {
4748
Name: user3.Name,
4849
UserName: user3.Name,
4950
FullName: user3.FullName,
51+
Email: user3.Email,
5052
AvatarURL: user3.AvatarLink(db.DefaultContext),
5153
Description: "",
5254
Website: "",
@@ -106,6 +108,7 @@ func TestMyOrgs(t *testing.T) {
106108
Name: user17.Name,
107109
UserName: user17.Name,
108110
FullName: user17.FullName,
111+
Email: user17.Email,
109112
AvatarURL: user17.AvatarLink(db.DefaultContext),
110113
Description: "",
111114
Website: "",
@@ -117,6 +120,7 @@ func TestMyOrgs(t *testing.T) {
117120
Name: user3.Name,
118121
UserName: user3.Name,
119122
FullName: user3.FullName,
123+
Email: user3.Email,
120124
AvatarURL: user3.AvatarLink(db.DefaultContext),
121125
Description: "",
122126
Website: "",

web_src/css/org.css

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,11 @@
118118
margin-bottom: 10px;
119119
}
120120

121-
.organization.profile #org-info .meta .item {
122-
display: inline-block;
123-
margin-right: 10px;
124-
}
125-
126-
.organization.profile #org-info .meta .item .icon {
127-
margin-right: 5px;
121+
.organization.profile #org-info .meta {
122+
display: flex;
123+
align-items: center;
124+
flex-wrap: wrap;
125+
gap: 8px;
128126
}
129127

130128
.organization.profile .ui.top.header .ui.right {

0 commit comments

Comments
 (0)