diff --git a/src/main/scala/code/snippet/Nav.scala b/src/main/scala/code/snippet/Nav.scala index aa412057..bf7a3d92 100644 --- a/src/main/scala/code/snippet/Nav.scala +++ b/src/main/scala/code/snippet/Nav.scala @@ -68,6 +68,8 @@ class Nav { def eraseMenu = "* * " #> "" + + def views: net.liftweb.util.CssSel = { val url = S.uri.split("/", 0) if (url.size > 4) { @@ -114,7 +116,7 @@ class Nav { if(hasOwnerPermissions) { val editViewsUrl = "/banks/" + url(2) + "/accounts/" + url(4) + "/views/list" ".navlink [href]" #> { editViewsUrl } & - ".navlink *" #> "Views & Permissions" & + ".navlink *" #> "Views" & ".navlink [class+]" #> markIfSelected(editViewsUrl) } else eraseMenu } diff --git a/src/main/scala/code/snippet/PermissionManagement.scala b/src/main/scala/code/snippet/PermissionManagement.scala index 2b21be14..8048f55e 100644 --- a/src/main/scala/code/snippet/PermissionManagement.scala +++ b/src/main/scala/code/snippet/PermissionManagement.scala @@ -23,6 +23,9 @@ import net.liftweb.http.js.JsCmds.SetHtml import scala.xml.Text import net.liftweb.http.js.jquery.JqJsCmds.Show + +import code.util.Helper._ + case class PermissionsUrlParams(bankId : String, accountId: String) case class ClickJson(userId: String, checked: Boolean, viewId : String) @@ -69,8 +72,8 @@ class PermissionManagement(params : (PermissionsJson, AccountJson, List[ViewJson return JSON.stringify(json); } """).cmd - - def accountInfo = ".account-label *" #> accountJson.label.getOrElse("---") + + def accountInfo = ".account-label *" #> getAccountTitle(accountJson) def accountViewHeaders = { val viewNames : List[String] = nonPublicViews.map(_.short_name.getOrElse("")) diff --git a/src/main/scala/code/snippet/TransactionsList.scala b/src/main/scala/code/snippet/TransactionsList.scala index 5fc2caa9..6afe53a3 100644 --- a/src/main/scala/code/snippet/TransactionsList.scala +++ b/src/main/scala/code/snippet/TransactionsList.scala @@ -46,6 +46,7 @@ import java.util.Currency import code.lib.ObpJson._ import code.lib._ import net.liftweb.json.JsonDSL._ +import code.util.Helper._ case class TransactionsListURLParams(bankId: String, accountId: String, viewId: String) @@ -412,19 +413,8 @@ Used in transactions list } def accountLabel = { - val hasManagementAccess = { - val availableViews = accountJson.views_available.toList.flatten - availableViews.exists(view => view.id == Some("owner")) - } - var label = accountJson.label.getOrElse("") - if (label.isEmpty) { - if (hasManagementAccess) - label = accountJson.number.getOrElse("") - else - label = accountJson.id.getOrElse("") - } - - "#accountShortDiscription *" #> label + val accountTitle = getAccountTitle(accountJson) + "#accountShortDescription *" #> accountTitle } /* LocalStorage.getAccount(url(2), url(4)) match { diff --git a/src/main/scala/code/snippet/ViewsOverview.scala b/src/main/scala/code/snippet/ViewsOverview.scala index 2e316144..0a8fcc73 100644 --- a/src/main/scala/code/snippet/ViewsOverview.scala +++ b/src/main/scala/code/snippet/ViewsOverview.scala @@ -1,5 +1,6 @@ package code.snippet +import code.util.Helper._ import net.liftweb.http.js.JE.{Call, Str} import net.liftweb.http.js.JsCmd import net.liftweb.util.Helpers._ @@ -10,7 +11,7 @@ import net.liftweb.http.{S, SHtml} import net.liftweb.json.JsonAST.JValue import net.liftweb.json._ import net.liftweb.http.js.JsCmds.{SetHtml, Alert, RedirectTo} -import net.liftweb.common.{Loggable, Box} +import net.liftweb.common.{Full, Loggable, Box} import code.lib.ObpAPI import net.liftweb.http.SHtml.{text,ajaxSubmit, ajaxButton} import ObpAPI.{addView, deleteView, updateAccountLabel, getAccount} @@ -35,6 +36,21 @@ class ViewsOverview(viewsDataJson: ViewsDataJSON) extends Loggable { val bank = viewsDataJson.bankId val account = viewsDataJson.accountId + + // Get the Account Title + // TODO put this into code.util.Helper + def getAccountTitleFromAccount : String = { + val accountJsonBox = getAccount(bank, account, "owner") + + val accountTitle = accountJsonBox match { + case Full(accountJson) => getAccountTitle(accountJson) + case _ => "Unknown Account" + } + accountTitle + } + + def setAccountTitle = ".account_title *" #> getAccountTitleFromAccount + def getTableContent(xhtml: NodeSeq) :NodeSeq = { //add ajax callback to save view @@ -183,13 +199,15 @@ class ViewsOverview(viewsDataJson: ViewsDataJSON) extends Loggable { val msg = "Sorry, a View with that name already exists." Call("socialFinanceNotifications.notifyError", msg).cmd } else { + // This only adds the view (does not grant the current user access) val result = addView(bank, account, newViewName) if (result.isDefined) { - val msg = "View " + newViewName + " has been created" + val msg = "View " + newViewName + " has been created. Please use the Access tab to grant yourself or others access." Call("socialFinanceNotifications.notify", msg).cmd - //reload page for new view to be shown - RedirectTo("") + // After creation, current user does not have access so, we show message above. + // TODO: Redirect to a page where user can give him/her self access - and/or grant access automatically. + // For now, don't reload so user can see the message above // reload page for new view to be shown // RedirectTo("") } else { val msg = "View " + newViewName + " could not be created" Call("socialFinanceNotifications.notifyError", msg).cmd @@ -215,6 +233,8 @@ class ViewsOverview(viewsDataJson: ViewsDataJSON) extends Loggable { if (result.isDefined) { val msg = "Label " + newLabel + " has been set" Call("socialFinanceNotifications.notify", msg).cmd + // So we can see the new account title which may use the updated label + RedirectTo("") } else { val msg = "Sorry, Label" + newLabel + " could not be set ("+ result +")" Call("socialFinanceNotifications.notifyError", msg).cmd diff --git a/src/main/scala/code/util/Helper.scala b/src/main/scala/code/util/Helper.scala new file mode 100644 index 00000000..99b5c750 --- /dev/null +++ b/src/main/scala/code/util/Helper.scala @@ -0,0 +1,36 @@ +package code.util + +import code.lib.ObpJson.AccountJson + + +object Helper { + + + +/* +Returns a string which can be used for the title of the account +*/ + def getAccountTitle(accountJson: AccountJson ) : String = { + + // TODO rewrite in more idiomatic style + var title = accountJson.label.getOrElse("") + if (title.isEmpty) { + if (hasManagementAccess(accountJson)) + title = accountJson.number.getOrElse("") + else + title = accountJson.id.getOrElse("") + } + title + } + + + def hasManagementAccess (accountJson: AccountJson ) : Boolean = { + val availableViews = accountJson.views_available.toList.flatten + availableViews.exists(view => view.id == Some("owner")) + } + + + + + +} diff --git a/src/main/webapp/banks/star/accounts/star/permissions.html b/src/main/webapp/banks/star/accounts/star/permissions.html index 2875b87f..9d5f37a4 100644 --- a/src/main/webapp/banks/star/accounts/star/permissions.html +++ b/src/main/webapp/banks/star/accounts/star/permissions.html @@ -30,8 +30,10 @@ Berlin 13359, Germany -->