Skip to content

Commit a7e8273

Browse files
authored
Fix the truncate and alignment problem for some admin tables (#26042)
Some "text truncate email" code were just copied&pasted, they are not suitable for most admin tables. For the table layouts, some "max-width" helpers could be very helpful. At least, we can get rid of the confusing "email" CSS class. ![image](https://github.com/go-gitea/gitea/assets/2114189/0b0bd068-56fc-41cf-b4a3-ed45eb797401) ![image](https://github.com/go-gitea/gitea/assets/2114189/e7f843a3-5f46-4205-b383-4c7ef647ce83) ![image](https://github.com/go-gitea/gitea/assets/2114189/ce8d65e1-7e03-466e-a03b-9bd33815da91)
1 parent acc74c2 commit a7e8273

File tree

6 files changed

+16
-44
lines changed

6 files changed

+16
-44
lines changed

templates/admin/emails/list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
{{range .Emails}}
4848
<tr>
4949
<td><a href="{{AppSubUrl}}/{{.Name | PathEscape}}">{{.Name}}</a></td>
50-
<td><span class="text truncate">{{.FullName}}</span></td>
51-
<td><span class="text email">{{.Email}}</span></td>
50+
<td class="gt-ellipsis gt-max-width-12rem">{{.FullName}}</td>
51+
<td class="gt-ellipsis gt-max-width-12rem">{{.Email}}</td>
5252
<td>{{if .IsPrimary}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td>
5353
<td>
5454
{{if .CanChange}}

templates/admin/packages/list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
{{end}}
5757
</td>
5858
<td>{{.Package.Type.Name}}</td>
59-
<td class="text truncate email">{{.Package.Name}}</td>
60-
<td><a href="{{.FullWebLink}}" class="text truncate email">{{.Version.Version}}</a></td>
59+
<td class="gt-ellipsis gt-max-width-12rem">{{.Package.Name}}</td>
60+
<td class="gt-ellipsis gt-max-width-12rem"><a href="{{.FullWebLink}}">{{.Version.Version}}</a></td>
6161
<td><a href="{{.Creator.HomeLink}}">{{.Creator.Name}}</a></td>
6262
<td>
6363
{{if .Repository}}

templates/admin/user/list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<tr>
8686
<td>{{.ID}}</td>
8787
<td><a href="{{.HomeLink}}">{{.Name}}</a></td>
88-
<td><span class="text truncate email">{{.Email}}</span></td>
88+
<td class="gt-ellipsis gt-max-width-12rem">{{.Email}}</td>
8989
<td>{{if .IsActive}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td>
9090
<td>{{if .IsAdmin}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td>
9191
<td>{{if .IsRestricted}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td>

tests/integration/auth_ldap_test.go

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -226,45 +226,20 @@ func TestLDAPUserSync(t *testing.T) {
226226
addAuthSourceLDAP(t, "", "")
227227
auth.SyncExternalUsers(context.Background(), true)
228228

229-
session := loginUser(t, "user1")
230229
// Check if users exists
231-
for _, u := range gitLDAPUsers {
232-
req := NewRequest(t, "GET", "/admin/users?q="+u.UserName)
233-
resp := session.MakeRequest(t, req, http.StatusOK)
234-
235-
htmlDoc := NewHTMLParser(t, resp.Body)
236-
237-
tr := htmlDoc.doc.Find("table.table tbody tr")
238-
if !assert.True(t, tr.Length() == 1) {
239-
continue
240-
}
241-
tds := tr.Find("td")
242-
if !assert.True(t, tds.Length() > 0) {
243-
continue
244-
}
245-
assert.Equal(t, u.UserName, strings.TrimSpace(tds.Find("td:nth-child(2) a").Text()))
246-
assert.Equal(t, u.Email, strings.TrimSpace(tds.Find("td:nth-child(3) span").Text()))
247-
if u.IsAdmin {
248-
assert.True(t, tds.Find("td:nth-child(5) svg").HasClass("octicon-check"))
249-
} else {
250-
assert.True(t, tds.Find("td:nth-child(5) svg").HasClass("octicon-x"))
251-
}
252-
if u.IsRestricted {
253-
assert.True(t, tds.Find("td:nth-child(6) svg").HasClass("octicon-check"))
254-
} else {
255-
assert.True(t, tds.Find("td:nth-child(6) svg").HasClass("octicon-x"))
256-
}
230+
for _, gitLDAPUser := range gitLDAPUsers {
231+
dbUser, err := user_model.GetUserByName(db.DefaultContext, gitLDAPUser.UserName)
232+
assert.NoError(t, err)
233+
assert.Equal(t, gitLDAPUser.UserName, dbUser.Name)
234+
assert.Equal(t, gitLDAPUser.Email, dbUser.Email)
235+
assert.Equal(t, gitLDAPUser.IsAdmin, dbUser.IsAdmin)
236+
assert.Equal(t, gitLDAPUser.IsRestricted, dbUser.IsRestricted)
257237
}
258238

259239
// Check if no users exist
260-
for _, u := range otherLDAPUsers {
261-
req := NewRequest(t, "GET", "/admin/users?q="+u.UserName)
262-
resp := session.MakeRequest(t, req, http.StatusOK)
263-
264-
htmlDoc := NewHTMLParser(t, resp.Body)
265-
266-
tr := htmlDoc.doc.Find("table.table tbody tr")
267-
assert.True(t, tr.Length() == 0)
240+
for _, otherLDAPUser := range otherLDAPUsers {
241+
_, err := user_model.GetUserByName(db.DefaultContext, otherLDAPUser.UserName)
242+
assert.True(t, user_model.IsErrUserNotExist(err))
268243
}
269244
}
270245

web_src/css/admin.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
margin: 12px -1rem -1rem;
2727
}
2828

29-
.admin.user table.table .email {
30-
max-width: 200px;
31-
}
32-
3329
.admin dl.admin-dl-horizontal {
3430
padding: 1em;
3531
margin: 0;

web_src/css/helpers.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Gitea's private styles use `g-` prefix.
5252
text-overflow: ellipsis;
5353
}
5454

55+
.gt-max-width-12rem { max-width: 12rem !important; }
5556
.gt-max-width-24rem { max-width: 24rem !important; }
5657

5758
/* below class names match Tailwind CSS */

0 commit comments

Comments
 (0)