diff --git a/src/main/scala/app/AccountController.scala b/src/main/scala/app/AccountController.scala index e6a0632..acf066f 100644 --- a/src/main/scala/app/AccountController.scala +++ b/src/main/scala/app/AccountController.scala @@ -42,14 +42,23 @@ */ get("/:userName") { val userName = params("userName") - getAccountByUserName(userName).map { x => + getAccountByUserName(userName).map { account => params.getOrElse("tab", "repositories") match { // Public Activity - case "activity" => account.html.activity(x, getActivitiesByUser(userName, true)) + case "activity" => + _root_.account.html.activity(account, + if(account.isGroupAccount) Nil else getGroupsByUserName(userName), + getActivitiesByUser(userName, true)) + // Members - case "members" if(x.isGroupAccount) => account.html.members(x, getGroupMembers(x.userName)) + case "members" if(account.isGroupAccount) => + _root_.account.html.members(account, getGroupMembers(account.userName)) + // Repositories - case _ => account.html.repositories(x, getVisibleRepositories(userName, baseUrl, context.loginAccount.map(_.userName))) + case _ => + _root_.account.html.repositories(account, + if(account.isGroupAccount) Nil else getGroupsByUserName(userName), + getVisibleRepositories(userName, baseUrl, context.loginAccount.map(_.userName))) } } getOrElse NotFound } diff --git a/src/main/scala/app/UserManagementController.scala b/src/main/scala/app/UserManagementController.scala index 7544ee5..08f14d8 100644 --- a/src/main/scala/app/UserManagementController.scala +++ b/src/main/scala/app/UserManagementController.scala @@ -17,9 +17,11 @@ case class EditUserForm(userName: String, password: Option[String], mailAddress: String, isAdmin: Boolean, url: Option[String], fileId: Option[String], clearImage: Boolean) - case class NewGroupForm(groupName: String, fileId: Option[String], memberNames: Option[String]) + case class NewGroupForm(groupName: String, url: Option[String], fileId: Option[String], + memberNames: Option[String]) - case class EditGroupForm(groupName: String, fileId: Option[String], memberNames: Option[String], clearImage: Boolean) + case class EditGroupForm(groupName: String, url: Option[String], fileId: Option[String], + memberNames: Option[String], clearImage: Boolean) val newUserForm = mapping( "userName" -> trim(label("Username" , text(required, maxlength(100), identifier, uniqueUserName))), @@ -42,12 +44,14 @@ val newGroupForm = mapping( "groupName" -> trim(label("Group name" , text(required, maxlength(100), identifier))), + "url" -> trim(label("URL" , optional(text(maxlength(200))))), "fileId" -> trim(label("File ID" , optional(text()))), "memberNames" -> trim(label("Member Names" , optional(text()))) )(NewGroupForm.apply) val editGroupForm = mapping( "groupName" -> trim(label("Group name" , text(required, maxlength(100), identifier))), + "url" -> trim(label("URL" , optional(text(maxlength(200))))), "fileId" -> trim(label("File ID" , optional(text()))), "memberNames" -> trim(label("Member Names" , optional(text()))), "clearImage" -> trim(label("Clear image" , boolean())) @@ -96,7 +100,7 @@ }) post("/admin/users/_newgroup", newGroupForm)(adminOnly { form => - createGroup(form.groupName) + createGroup(form.groupName, form.url) updateGroupMembers(form.groupName, form.memberNames.map(_.split(",").toList).getOrElse(Nil)) updateImage(form.groupName, form.fileId, false) redirect("/admin/users") @@ -110,6 +114,8 @@ post("/admin/users/:groupName/_editgroup", editGroupForm)(adminOnly { form => val groupName = params("groupName") getAccountByUserName(groupName).map { account => + updateGroup(groupName, form.url) + val memberNames = form.memberNames.map(_.split(",").toList).getOrElse(Nil) updateGroupMembers(form.groupName, memberNames) diff --git a/src/main/scala/service/AccountService.scala b/src/main/scala/service/AccountService.scala index 769f9b7..3f828e3 100644 --- a/src/main/scala/service/AccountService.scala +++ b/src/main/scala/service/AccountService.scala @@ -46,22 +46,24 @@ def updateLastLoginDate(userName: String): Unit = Accounts.filter(_.userName is userName.bind).map(_.lastLoginDate).update(currentDate) - def createGroup(groupName: String): Unit = + def createGroup(groupName: String, url: Option[String]): Unit = Accounts insert Account( userName = groupName, password = "", mailAddress = groupName + "@devnull", isAdmin = false, - url = None, + url = url, registeredDate = currentDate, updatedDate = currentDate, lastLoginDate = None, image = None, isGroupAccount = true) + def updateGroup(groupName: String, url: Option[String]): Unit = + Accounts.filter(_.userName is groupName.bind).map(_.url.?).update(url) + def updateGroupMembers(groupName: String, members: List[String]): Unit = { Query(GroupMembers).filter(_.groupName is groupName.bind).delete - members.foreach { userName => GroupMembers insert GroupMember (groupName, userName) } diff --git a/src/main/twirl/account/activity.scala.html b/src/main/twirl/account/activity.scala.html index 29b2982..1f2cefc 100644 --- a/src/main/twirl/account/activity.scala.html +++ b/src/main/twirl/account/activity.scala.html @@ -1,23 +1,6 @@ -@(account: model.Account, activities: List[model.Activity])(implicit context: app.Context) +@(account: model.Account, groupNames: List[String], activities: List[model.Activity])(implicit context: app.Context) @import context._ @import view.helpers._ -@html.main(account.userName){ -