use description as bio in user account type

This commit is contained in:
nazoking
2017-01-16 01:37:19 +09:00
parent 53537eaa09
commit cd836f331e
15 changed files with 80 additions and 52 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<changeSet>
<addColumn tableName="ACCOUNT">
<column name="GROUP_DESCRIPTION" type="text" nullable="true" />
<column name="DESCRIPTION" type="text" nullable="true" />
</addColumn>
</changeSet>

View File

@@ -29,10 +29,10 @@ trait AccountControllerBase extends AccountManagementControllerBase {
with AccessTokenService with WebHookService with RepositoryCreationService =>
case class AccountNewForm(userName: String, password: String, fullName: String, mailAddress: String,
url: Option[String], fileId: Option[String])
description: Option[String], url: Option[String], fileId: Option[String])
case class AccountEditForm(password: Option[String], fullName: String, mailAddress: String,
url: Option[String], fileId: Option[String], clearImage: Boolean)
description: Option[String], url: Option[String], fileId: Option[String], clearImage: Boolean)
case class SshKeyForm(title: String, publicKey: String)
@@ -43,6 +43,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
"password" -> trim(label("Password" , text(required, maxlength(20)))),
"fullName" -> trim(label("Full Name" , text(required, maxlength(100)))),
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100), uniqueMailAddress()))),
"description" -> trim(label("bio" , optional(text()))),
"url" -> trim(label("URL" , optional(text(maxlength(200))))),
"fileId" -> trim(label("File ID" , optional(text())))
)(AccountNewForm.apply)
@@ -51,6 +52,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
"password" -> trim(label("Password" , optional(text(maxlength(20))))),
"fullName" -> trim(label("Full Name" , text(required, maxlength(100)))),
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100), uniqueMailAddress("userName")))),
"description" -> trim(label("bio" , optional(text()))),
"url" -> trim(label("URL" , optional(text(maxlength(200))))),
"fileId" -> trim(label("File ID" , optional(text()))),
"clearImage" -> trim(label("Clear image" , boolean()))
@@ -65,12 +67,12 @@ trait AccountControllerBase extends AccountManagementControllerBase {
"note" -> trim(label("Token", text(required, maxlength(100))))
)(PersonalTokenForm.apply)
case class NewGroupForm(groupName: String, groupDescription: Option[String], url: Option[String], fileId: Option[String], members: String)
case class EditGroupForm(groupName: String, groupDescription: Option[String], url: Option[String], fileId: Option[String], members: String, clearImage: Boolean)
case class NewGroupForm(groupName: String, description: Option[String], url: Option[String], fileId: Option[String], members: String)
case class EditGroupForm(groupName: String, description: Option[String], url: Option[String], fileId: Option[String], members: String, clearImage: Boolean)
val newGroupForm = mapping(
"groupName" -> trim(label("Group name" ,text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
"groupDescription" -> trim(label("Group description", optional(text()))),
"description" -> trim(label("Group description", optional(text()))),
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
"fileId" -> trim(label("File ID" ,optional(text()))),
"members" -> trim(label("Members" ,text(required, members)))
@@ -78,7 +80,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
val editGroupForm = mapping(
"groupName" -> trim(label("Group name" ,text(required, maxlength(100), identifier))),
"groupDescription" -> trim(label("Group description", optional(text()))),
"description" -> trim(label("Group description", optional(text()))),
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
"fileId" -> trim(label("File ID" ,optional(text()))),
"members" -> trim(label("Members" ,text(required, members))),
@@ -169,6 +171,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
password = form.password.map(sha1).getOrElse(account.password),
fullName = form.fullName,
mailAddress = form.mailAddress,
description = form.description,
url = form.url))
updateImage(userName, form.fileId, form.clearImage)
@@ -268,7 +271,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
post("/register", newForm){ form =>
if(context.settings.allowAccountRegistration){
createAccount(form.userName, sha1(form.password), form.fullName, form.mailAddress, false, form.url)
createAccount(form.userName, sha1(form.password), form.fullName, form.mailAddress, false, form.description, form.url)
updateImage(form.userName, form.fileId, false)
redirect("/signin")
} else NotFound()
@@ -279,7 +282,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
})
post("/groups/new", newGroupForm)(usersOnly { form =>
createGroup(form.groupName, form.url, form.groupDescription)
createGroup(form.groupName, form.description, form.url)
updateGroupMembers(form.groupName, form.members.split(",").map {
_.split(":") match {
case Array(userName, isManager) => (userName, isManager.toBoolean)
@@ -317,7 +320,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
}
}.toList){ case (groupName, members) =>
getAccountByUserName(groupName, true).map { account =>
updateGroup(groupName, form.url, form.groupDescription, false)
updateGroup(groupName, form.description, form.url, false)
// Update GROUP_MEMBER
updateGroupMembers(form.groupName, members)

View File

@@ -91,16 +91,16 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
case class NewUserForm(userName: String, password: String, fullName: String,
mailAddress: String, isAdmin: Boolean,
url: Option[String], fileId: Option[String])
description: Option[String], url: Option[String], fileId: Option[String])
case class EditUserForm(userName: String, password: Option[String], fullName: String,
mailAddress: String, isAdmin: Boolean, url: Option[String],
mailAddress: String, isAdmin: Boolean, description: Option[String], url: Option[String],
fileId: Option[String], clearImage: Boolean, isRemoved: Boolean)
case class NewGroupForm(groupName: String, groupDescription: Option[String], url: Option[String], fileId: Option[String],
case class NewGroupForm(groupName: String, description: Option[String], url: Option[String], fileId: Option[String],
members: String)
case class EditGroupForm(groupName: String, groupDescription: Option[String], url: Option[String], fileId: Option[String],
case class EditGroupForm(groupName: String, description: Option[String], url: Option[String], fileId: Option[String],
members: String, clearImage: Boolean, isRemoved: Boolean)
@@ -110,6 +110,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
"fullName" -> trim(label("Full Name" ,text(required, maxlength(100)))),
"mailAddress" -> trim(label("Mail Address" ,text(required, maxlength(100), uniqueMailAddress()))),
"isAdmin" -> trim(label("User Type" ,boolean())),
"description" -> trim(label("bio" ,optional(text()))),
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
"fileId" -> trim(label("File ID" ,optional(text())))
)(NewUserForm.apply)
@@ -120,6 +121,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
"fullName" -> trim(label("Full Name" ,text(required, maxlength(100)))),
"mailAddress" -> trim(label("Mail Address" ,text(required, maxlength(100), uniqueMailAddress("userName")))),
"isAdmin" -> trim(label("User Type" ,boolean())),
"description" -> trim(label("bio" ,optional(text()))),
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
"fileId" -> trim(label("File ID" ,optional(text()))),
"clearImage" -> trim(label("Clear image" ,boolean())),
@@ -128,7 +130,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
val newGroupForm = mapping(
"groupName" -> trim(label("Group name" ,text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
"groupDescription" -> trim(label("Group description", optional(text()))),
"description" -> trim(label("Group description", optional(text()))),
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
"fileId" -> trim(label("File ID" ,optional(text()))),
"members" -> trim(label("Members" ,text(required, members)))
@@ -136,7 +138,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
val editGroupForm = mapping(
"groupName" -> trim(label("Group name" ,text(required, maxlength(100), identifier))),
"groupDescription" -> trim(label("Group description", optional(text()))),
"description" -> trim(label("Group description", optional(text()))),
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
"fileId" -> trim(label("File ID" ,optional(text()))),
"members" -> trim(label("Members" ,text(required, members))),
@@ -198,7 +200,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
})
post("/admin/users/_newuser", newUserForm)(adminOnly { form =>
createAccount(form.userName, sha1(form.password), form.fullName, form.mailAddress, form.isAdmin, form.url)
createAccount(form.userName, sha1(form.password), form.fullName, form.mailAddress, form.isAdmin, form.description, form.url)
updateImage(form.userName, form.fileId, false)
redirect("/admin/users")
})
@@ -232,6 +234,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
fullName = form.fullName,
mailAddress = form.mailAddress,
isAdmin = form.isAdmin,
description = form.description,
url = form.url,
isRemoved = form.isRemoved))
@@ -246,7 +249,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
})
post("/admin/users/_newgroup", newGroupForm)(adminOnly { form =>
createGroup(form.groupName, form.url, form.groupDescription)
createGroup(form.groupName, form.description, form.url)
updateGroupMembers(form.groupName, form.members.split(",").map {
_.split(":") match {
case Array(userName, isManager) => (userName, isManager.toBoolean)
@@ -269,7 +272,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
}
}.toList){ case (groupName, members) =>
getAccountByUserName(groupName, true).map { account =>
updateGroup(groupName, form.url, form.groupDescription, form.isRemoved)
updateGroup(groupName, form.url, form.description, form.isRemoved)
if(form.isRemoved){
// Remove from GROUP_MEMBER

View File

@@ -19,8 +19,8 @@ trait AccountComponent { self: Profile =>
val image = column[String]("IMAGE")
val groupAccount = column[Boolean]("GROUP_ACCOUNT")
val removed = column[Boolean]("REMOVED")
val groupDescription = column[String]("GROUP_DESCRIPTION")
def * = (userName, fullName, mailAddress, password, isAdmin, url.?, registeredDate, updatedDate, lastLoginDate.?, image.?, groupAccount, removed, groupDescription.?) <> (Account.tupled, Account.unapply)
val description = column[String]("DESCRIPTION")
def * = (userName, fullName, mailAddress, password, isAdmin, url.?, registeredDate, updatedDate, lastLoginDate.?, image.?, groupAccount, removed, description.?) <> (Account.tupled, Account.unapply)
}
}
@@ -37,5 +37,5 @@ case class Account(
image: Option[String],
isGroupAccount: Boolean,
isRemoved: Boolean,
groupDescription: Option[String]
description: Option[String]
)

View File

@@ -61,7 +61,7 @@ trait AccountService {
defaultAuthentication(userName, password)
}
case None => {
createAccount(ldapUserInfo.userName, "", ldapUserInfo.fullName, ldapUserInfo.mailAddress, false, None)
createAccount(ldapUserInfo.userName, "", ldapUserInfo.fullName, ldapUserInfo.mailAddress, false, None, None)
getAccountByUserName(ldapUserInfo.userName)
}
}
@@ -103,7 +103,7 @@ trait AccountService {
} else false
}
def createAccount(userName: String, password: String, fullName: String, mailAddress: String, isAdmin: Boolean, url: Option[String])
def createAccount(userName: String, password: String, fullName: String, mailAddress: String, isAdmin: Boolean, description: Option[String], url: Option[String])
(implicit s: Session): Unit =
Accounts insert Account(
userName = userName,
@@ -118,12 +118,12 @@ trait AccountService {
image = None,
isGroupAccount = false,
isRemoved = false,
groupDescription = None)
description = description)
def updateAccount(account: Account)(implicit s: Session): Unit =
Accounts
.filter { a => a.userName === account.userName.bind }
.map { a => (a.password, a.fullName, a.mailAddress, a.isAdmin, a.url.?, a.registeredDate, a.updatedDate, a.lastLoginDate.?, a.removed) }
.map { a => (a.password, a.fullName, a.mailAddress, a.isAdmin, a.url.?, a.registeredDate, a.updatedDate, a.lastLoginDate.?, a.removed, a.description.?) }
.update (
account.password,
account.fullName,
@@ -133,7 +133,8 @@ trait AccountService {
account.registeredDate,
currentDate,
account.lastLoginDate,
account.isRemoved)
account.isRemoved,
account.description)
def updateAvatarImage(userName: String, image: Option[String])(implicit s: Session): Unit =
Accounts.filter(_.userName === userName.bind).map(_.image.?).update(image)
@@ -141,7 +142,7 @@ trait AccountService {
def updateLastLoginDate(userName: String)(implicit s: Session): Unit =
Accounts.filter(_.userName === userName.bind).map(_.lastLoginDate).update(currentDate)
def createGroup(groupName: String, url: Option[String], description: Option[String])(implicit s: Session): Unit =
def createGroup(groupName: String, description: Option[String], url: Option[String])(implicit s: Session): Unit =
Accounts insert Account(
userName = groupName,
password = "",
@@ -155,12 +156,12 @@ trait AccountService {
image = None,
isGroupAccount = true,
isRemoved = false,
groupDescription = description)
description = description)
def updateGroup(groupName: String, url: Option[String], groupDescription: Option[String], removed: Boolean)(implicit s: Session): Unit =
def updateGroup(groupName: String, description: Option[String], url: Option[String], removed: Boolean)(implicit s: Session): Unit =
Accounts.filter(_.userName === groupName.bind)
.map(t => (t.url.?, t.groupDescription.?, t.removed))
.update(url, groupDescription, removed)
.map(t => (t.url.?, t.description.?, t.removed))
.update(url, description, removed)
def updateGroupMembers(groupName: String, members: List[(String, Boolean)])(implicit s: Session): Unit = {
GroupMembers.filter(_.groupName === groupName.bind).delete

View File

@@ -37,6 +37,11 @@
<input type="text" name="url" id="url" class="form-control" value="@account.url"/>
<span id="error-url" class="error"></span>
</fieldset>
<fieldset class="form-group">
<label for="description" class="strong">bio (optional):</label>
<textarea name="description" id="description" class="form-control">@account.description</textarea>
<span id="error-description" class="error"></span>
</fieldset>
</div>
<div class="col-md-6">
<fieldset class="form-group">

View File

@@ -23,9 +23,9 @@
</fieldset>
<fieldset class="form-group">
<label for="groupDescription" class="strong">Description (Optional)</label>
<input type="text" name="groupDescription" id="groupDescription"
value="@account.map(_.groupDescription)"
style="width: 300px;" />
<div>
<textarea name="description" id="description" class="form-control">@account.map(_.description)</textarea>
</div>
</fieldset>
<fieldset class="form-group">
<label for="avatar" class="strong">Image (Optional)</label>

View File

@@ -10,13 +10,11 @@
<p>@account.userName</p>
@account.fullName
</div>
@if(account.isGroupAccount) {
<div class="group-description">@account.groupDescription</div>
} else {
<div class="account-username">@account.groupDescription</div>
}
</div>
<div style="padding-left: 10px; padding-right: 10px;">
@account.description.map{ description =>
<p style="color: white;">@description</p>
}
@if(account.url.isDefined){
<p style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<i class="octicon octicon-home"></i> <a href="@account.url">@account.url</a>

View File

@@ -33,6 +33,11 @@
<input type="text" name="url" id="url" class="form-control" value=""/>
<span id="error-url" class="error"></span>
</fieldset>
<fieldset>
<label for="description" class="strong">bio (optional):</label>
<textarea name="description" id="description" class="form-control"></textarea>
<span id="error-description" class="error"></span>
</fieldset>
</div>
<div class="col-md-6">
<fieldset>

View File

@@ -66,6 +66,13 @@
</div>
<input type="text" name="url" id="url" class="form-control" value="@account.map(_.url)"/>
</fieldset>
<fieldset class="form-group">
<label class="strong">bio (Optional):</label>
<div>
<span id="error-description" class="error"></span>
</div>
<textarea name="description" id="description" class="form-control">@account.map(_.description)</textarea>
</fieldset>
</div>
<div class="col-md-6">
<fieldset class="form-group">

View File

@@ -26,8 +26,7 @@
</fieldset>
<fieldset class="form-group">
<label class="strong">Description (Optional)</label>
<input type="text" name="groupDescription" id="groupDescription"
value="@account.map(_.groupDescription)" />
<textarea name="description" id="description" class="form-control">@account.map(_.description)</textarea>
</fieldset>
<fieldset class="form-group">
<label for="avatar" class="strong">Image (Optional)</label>

View File

@@ -424,8 +424,7 @@ div.signin-form {
font-weight: bold;
}
.account-username,
.group-description {
.account-username {
margin-top: 10px;
font-size: 140%;
color: #888888;

View File

@@ -47,6 +47,14 @@ class AccountServiceSpec extends FunSuite with ServiceSpecBase {
val newAddress = "new mail address"
AccountService.updateAccount(user().copy(mailAddress = newAddress))
assert(user().mailAddress == newAddress)
val newUrl = Some("http://new.url.example/path")
AccountService.updateAccount(user().copy(url = newUrl))
assert(user().url == newUrl)
val newDescription = Some("http://new.url.example/path")
AccountService.updateAccount(user().copy(description = newDescription))
assert(user().description == newDescription)
}}
test("group") { withTestDB { implicit session =>
@@ -69,18 +77,18 @@ class AccountServiceSpec extends FunSuite with ServiceSpecBase {
}}
test("createGroup save description") { withTestDB { implicit session =>
AccountService.createGroup("some-group", None, Some("some clever description"))
AccountService.createGroup("some-group", Some("some clever description"), None)
val maybeGroup = AccountService.getAccountByUserName("some-group")
assert(maybeGroup.flatMap(_.groupDescription) == Some("some clever description"))
assert(maybeGroup.flatMap(_.description) == Some("some clever description"))
}}
test("updateGroup save description") { withTestDB { implicit session =>
AccountService.createGroup("a-group", None, None)
AccountService.updateGroup("a-group", None, Some("new description"), false)
AccountService.updateGroup("a-group", Some("new description"), None, false)
val group = AccountService.getAccountByUserName("a-group")
assert(group.flatMap(_.groupDescription) == Some("new description"))
assert(group.flatMap(_.description) == Some("new description"))
}}
}

View File

@@ -37,7 +37,7 @@ trait ServiceSpecBase {
}
def generateNewAccount(name:String)(implicit s:Session):Account = {
AccountService.createAccount(name, name, name, s"${name}@example.com", false, None)
AccountService.createAccount(name, name, name, s"${name}@example.com", false, None, None)
user(name)
}

View File

@@ -95,7 +95,7 @@ class AvatarImageProviderSpec extends FunSpec with MockitoSugar {
image = image,
isGroupAccount = false,
isRemoved = false,
groupDescription = None)
description = None)
private def createSystemSettings(useGravatar: Boolean) =
SystemSettings(