Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Organisations to have a E-Mail #25082

Merged
merged 18 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/structs/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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)"`
Expand All @@ -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)"`
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,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 E-Mail
settings.website = Website
settings.location = Location
settings.permission = Permissions
Expand Down
12 changes: 11 additions & 1 deletion routers/api/v1/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions routers/web/org/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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
Expand Down
1 change: 1 addition & 0 deletions services/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions services/forms/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"`
Expand Down
7 changes: 5 additions & 2 deletions templates/org/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
</div>
{{if $.RenderedDescription}}<div class="render-content markup">{{$.RenderedDescription|Str2html}}</div>{{end}}
<div class="text grey meta">
{{if .Org.Location}}<div class="item">{{svg "octicon-location"}} <span>{{.Org.Location}}</span></div>{{end}}
{{if .Org.Website}}<div class="item">{{svg "octicon-link"}} <a target="_blank" rel="noopener noreferrer me" href="{{.Org.Website}}">{{.Org.Website}}</a></div>{{end}}
{{if .Org.Location}}<div class="flex-text-block">{{svg "octicon-location"}} <span>{{.Org.Location}}</span></div>{{end}}
{{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}}
{{if $.IsSigned}}
{{if .Org.Email}}<div class="flex-text-block">{{svg "octicon-mail"}} <a class="muted" href="mailto:{{.Org.Email}}">{{.Org.Email}}</a></div>{{end}}
{{end}}
</div>
</div>
<div class="right menu">
Expand Down
4 changes: 4 additions & 0 deletions templates/org/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<label for="full_name">{{.locale.Tr "org.org_full_name_holder"}}</label>
<input id="full_name" name="full_name" value="{{.Org.FullName}}" maxlength="100">
</div>
<div class="field {{if .Err_Email}}error{{end}}">
<label for="email">{{.locale.Tr "org.settings.email"}}</label>
<input id="email" name="email" type="email" value="{{.Org.Email}}" maxlength="255">
</div>
<div class="field {{if .Err_Description}}error{{end}}">
<label for="description">{{$.locale.Tr "org.org_desc"}}</label>
<textarea id="description" name="description" rows="2" maxlength="255">{{.Org.Description}}</textarea>
Expand Down
12 changes: 12 additions & 0 deletions templates/swagger/v1_json.tmpl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/integration/api_user_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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: "",
Expand Down Expand Up @@ -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: "",
Expand All @@ -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: "",
Expand Down
12 changes: 5 additions & 7 deletions web_src/css/org.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,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 {
Expand Down