Skip to content

Commit

Permalink
#68 closed: "Show public user list with links to their profiles"
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Jul 26, 2011
1 parent 46078b6 commit 52571d6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ package sitemap

import xml.Text
import net.liftweb.sitemap.Loc
import net.liftweb.http.{RewriteResponse, ParsePath, RewriteRequest}
import net.liftweb.util.NamedPF
import net.liftweb.common.Full
import net.liftweb.mapper.By
import model.mapper.User
import net.liftweb.http.{NotFoundResponse, RewriteResponse, ParsePath, RewriteRequest}

/** Profile location parameter. */
case class ProfileLoc()
Expand All @@ -57,9 +57,7 @@ object ProfileStuff extends Loc[ProfileLoc] {
/** Rewrite location. */
override val rewrite: LocRewrite = Full(NamedPF("Profile Rewrite") {
case RewriteRequest(ParsePath("profile" :: username :: Nil, _, _, _), _, _)
if (User.superUser_? && !User.find(By(User.userName, username)).isEmpty) =>
if (!User.find(By(User.userName, username)).isEmpty) =>
(RewriteResponse("profile" :: Nil, Map("username" -> username)), ProfileLoc())
case RewriteRequest(ParsePath("profile" :: Nil, _, _, _), _, _) if (!User.loggedIn_?) =>
(RewriteResponse("" :: Nil), ProfileLoc())
})
}
4 changes: 2 additions & 2 deletions src/main/scala/scala/tools/colladoc/page/Profile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class Profile(rootPack: Package) extends scala.tools.colladoc.page.Template(root
<div id="profile_tabs">
<ul>
<li><a href="#profile_tab">Public Profile</a></li>
<li><a href="#account_admin_tab">Account Admin</a></li>
<li id="account_href"><a href="#account_admin_tab">Account Admin</a></li>
<li><a href="#comments_tab">Comments</a></li>
<li><a href="#discussion_comments_tab">Discussion Comments</a></li>
<li id="discussion_href"><a href="#discussion_comments_tab">Discussion Comments</a></li>
</ul>
<div id="profile_tab">
<profile:form />
Expand Down
52 changes: 44 additions & 8 deletions src/main/scala/scala/tools/colladoc/snippet/ProfileOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import net.liftweb.http.js.JsCmds.{Noop, RedirectTo, SetValById}
import net.liftweb.http.js.JE.Str
import net.liftweb.http.js.{JsCmds, JsCmd}
import page.{Template, History, Profile}
import net.liftweb.common.Full

/**
* User profile snippet.
Expand All @@ -46,7 +47,26 @@ class ProfileOps {

def title(xhtml: NodeSeq): NodeSeq = Text(getUser.userName.is)

def getUser = User.find(By(User.userName, username)).open_!
def getUser = {
val maybeUser = User.find(By(User.userName, username))
if (maybeUser.isEmpty)
S.redirectTo("/")
maybeUser.open_!
}

def public_?(): Boolean = {
if (!User.loggedIn_?)
return true
if (User.superUser_?)
return false
User.currentUser match {
case Full(u) =>
if (u == getUser)
return false
true
case _ => true
}
}

private def userForm(user: User): NodeSeq = {
def doSave(): JsCmd = {
Expand Down Expand Up @@ -109,6 +129,21 @@ class ProfileOps {
)
}

def publicProfile(user: User) = {
<lift:form class="form profile_form">
<fieldset>
<p>
<label>Username</label>
<span>{user.userName}</span>
</p>
<p>
<label>Full Name</label>
<span>{user.shortName}</span>
</p>
</fieldset>
</lift:form>
}

def changePasswordForm(user: User) = {
var oldPass, newPass, confirm: String = ""

Expand Down Expand Up @@ -211,13 +246,14 @@ class ProfileOps {
{dscs map dToHtml _}
</ul>

bind("profile", profile.body,
"form" -> userForm(user),
"change_password" -> changePasswordForm(user),
"delete_profile" -> deleteProfile(user),
"fullname" -> Text(fullname),
"comments" -> comments,
"discussion_comments" -> discussionComments
bind("profile",
profile.body,
"form" -> { if (!public_?) userForm(user) else publicProfile(user) },
"change_password" -> { if (!public_?) changePasswordForm(user) else NodeSeq.Empty },
"delete_profile" -> { if (!public_?) deleteProfile(user) else NodeSeq.Empty },
"discussion_comments" -> { if (!public_?) discussionComments else NodeSeq.Empty },
"fullname" -> Text(fullname),
"comments" -> comments
)
}
}
12 changes: 9 additions & 3 deletions src/main/webapp/scripts/coprofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
*/

$(document).ready(function() {
$("#profile_tabs").tabs();
$(".profile_form").validate();
$(".change_password_form").validate();
if ($("#account_admin_tab").children().length == 0)
$("#account_href").remove();

if ($("#discussion_comments_tab").children().length == 0)
$("#discussion_href").remove();

$("#profile_tabs").tabs();
$(".profile_form").validate();
$(".change_password_form").validate();
});

0 comments on commit 52571d6

Please sign in to comment.