diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/action.go | 40 | ||||
-rw-r--r-- | models/login.go | 13 | ||||
-rw-r--r-- | models/user.go | 7 |
3 files changed, 39 insertions, 21 deletions
diff --git a/models/action.go b/models/action.go index 9ecf67b4..4e5f461a 100644 --- a/models/action.go +++ b/models/action.go @@ -90,54 +90,66 @@ func (a *Action) AfterSet(colName string, _ xorm.Cell) { } } -func (a Action) GetOpType() int { +func (a *Action) GetOpType() int { return int(a.OpType) } -func (a Action) GetActUserName() string { +func (a *Action) GetActUserName() string { return a.ActUserName } -func (a Action) GetActEmail() string { +func (a *Action) ShortActUserName() string { + return base.EllipsisString(a.ActUserName, 20) +} + +func (a *Action) GetActEmail() string { return a.ActEmail } -func (a Action) GetRepoUserName() string { +func (a *Action) GetRepoUserName() string { return a.RepoUserName } -func (a Action) GetRepoName() string { +func (a *Action) ShortRepoUserName() string { + return base.EllipsisString(a.RepoUserName, 20) +} + +func (a *Action) GetRepoName() string { return a.RepoName } -func (a Action) GetRepoPath() string { - return path.Join(a.RepoUserName, a.RepoName) +func (a *Action) ShortRepoName() string { + return base.EllipsisString(a.RepoName, 33) +} + +func (a *Action) GetRepoPath() string { + return path.Join(a.ShortRepoUserName(), a.ShortRepoName()) } -func (a Action) GetRepoLink() string { +func (a *Action) GetRepoLink() string { if len(setting.AppSubUrl) > 0 { return path.Join(setting.AppSubUrl, a.GetRepoPath()) } return "/" + a.GetRepoPath() } -func (a Action) GetBranch() string { +func (a *Action) GetBranch() string { return a.RefName } -func (a Action) GetContent() string { +func (a *Action) GetContent() string { return a.Content } -func (a Action) GetCreate() time.Time { +func (a *Action) GetCreate() time.Time { return a.Created } -func (a Action) GetIssueInfos() []string { +func (a *Action) GetIssueInfos() []string { return strings.SplitN(a.Content, "|", 2) } -func (a Action) GetIssueTitle() string { +func (a *Action) GetIssueTitle() string { index := com.StrTo(a.GetIssueInfos()[0]).MustInt64() issue, err := GetIssueByIndex(a.RepoID, index) if err != nil { @@ -147,7 +159,7 @@ func (a Action) GetIssueTitle() string { return issue.Name } -func (a Action) GetIssueContent() string { +func (a *Action) GetIssueContent() string { index := com.StrTo(a.GetIssueInfos()[0]).MustInt64() issue, err := GetIssueByIndex(a.RepoID, index) if err != nil { diff --git a/models/login.go b/models/login.go index e36171a3..df890509 100644 --- a/models/login.go +++ b/models/login.go @@ -105,10 +105,21 @@ type LoginSource struct { Updated time.Time `xorm:"UPDATED"` } +// Cell2Int64 converts a xorm.Cell type to int64, +// and handles possible irregular cases. +func Cell2Int64(val xorm.Cell) int64 { + switch (*val).(type) { + case []uint8: + log.Trace("Cell2Int64 ([]uint8): %v", *val) + return com.StrTo(string((*val).([]uint8))).MustInt64() + } + return (*val).(int64) +} + func (source *LoginSource) BeforeSet(colName string, val xorm.Cell) { switch colName { case "type": - switch LoginType((*val).(int64)) { + switch LoginType(Cell2Int64(val)) { case LOGIN_LDAP, LOGIN_DLDAP: source.Cfg = new(LDAPConfig) case LOGIN_SMTP: diff --git a/models/user.go b/models/user.go index f648a8ab..5c43a23a 100644 --- a/models/user.go +++ b/models/user.go @@ -429,13 +429,8 @@ func (u *User) DisplayName() string { return u.Name } -// ShortName returns shorted user name with given maximum length, -// it adds "..." at the end if user name has more length than maximum. func (u *User) ShortName(length int) string { - if len(u.Name) < length { - return u.Name - } - return u.Name[:length] + "..." + return base.EllipsisString(u.Name, length) } // IsUserExist checks if given user name exist, |