Skip to content

Commit

Permalink
added User.banned field
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Jul 27, 2011
1 parent 80a2755 commit a5cf377
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/scala/tools/colladoc/api/GridAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import net.liftweb.mapper.{OrderBy, Descending, Ascending}
object GridAPI extends RestHelper {
serve {
case "grid" :: "users" :: _ Get _ =>
if (User.superUser_?) {
if (User.validSuperUser_?) {
for {
Spage <- S.param("page") ?~ "page parameter missing" ~> 400
Srows <- S.param("rows") ?~ "rows parameter missing" ~> 400
Expand Down
19 changes: 18 additions & 1 deletion src/main/scala/scala/tools/colladoc/model/mapper/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,16 @@ class User extends ProtoUser[User] with OneToMany[Long, User] {
override def defaultValue = false
}

object banned extends MappedBoolean(this) {
override def defaultValue = false
}

def userNameDisplayName = S.??("user.name")

def deleted_? = deleted.is == true



/** User comment changes. */
object comments extends MappedOneToMany(Comment, Comment.user)

Expand All @@ -79,6 +85,7 @@ class User extends ProtoUser[User] with OneToMany[Long, User] {
<cell>{profileHyperlink.toString}</cell>
<cell><row:superuser /></cell>
<cell><row:delete /></cell>
<cell><row:banned /></cell>
</row>

bind("row", row,
Expand All @@ -90,7 +97,13 @@ class User extends ProtoUser[User] with OneToMany[Long, User] {
}).toString,
"delete" -> SHtml.ajaxCheckbox(
deleted_?, bool => {
deleted(bool).save
deleted(bool)
save
Noop
}).toString,
"banned" -> SHtml.ajaxCheckbox(
banned, bool => {
banned(bool)
save
Noop
}).toString
Expand Down Expand Up @@ -120,6 +133,10 @@ object User extends User with KeyedMetaMapper[Long, User] {
/** Whether currently logged in user is superuser */
def superUser_? : Boolean = currentUser.map(_.superUser.is) openOr false

def banned_? = currentUser.map(_.banned.is) openOr true

def validSuperUser_? = superUser_? && !User.banned_?

/** Whether any user is logged in. */
def loggedIn_? = currentUserId.isDefined
/** Log in user with given identifier. */
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scala/tools/colladoc/page/Index.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Index(universe: Universe) extends tools.nsc.doc.html.page.Index(universe)
</a>
</div>
<ul class="usernav">
{ if (User.superUser_?)
{ if (User.validSuperUser_?)
<li><a href="/settings" target="template">Settings</a></li>
}
<li><a href="/history" target="template">History</a></li>
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scala/tools/colladoc/page/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Settings(rootPack: Package) extends scala.tools.colladoc.page.Template(roo
/** Page body. */
override val body =
<body class="settings">
{ if (User.superUser_?) {
{ if (User.validSuperUser_?) {
<div id="definition">
<img src="images/settings_big.png" />
<h1>Settings</h1>
Expand Down
22 changes: 11 additions & 11 deletions src/main/scala/scala/tools/colladoc/page/Template.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class Template(tpl: DocTemplateEntity) extends tools.nsc.doc.html.page.Template(
<ul id="discussion_thread">
{discussionComments map (d => discussionToHtmlWithActions(d, 0))}
</ul>
{ discussionCommentAddButton }
{ if (!User.banned_?) discussionCommentAddButton }
</div>
</div>

Expand Down Expand Up @@ -225,9 +225,9 @@ class Template(tpl: DocTemplateEntity) extends tools.nsc.doc.html.page.Template(
/** Render discussion comment with actions. */
private def discussionToHtmlWithActions(d: Discussion, level: Int = 0): NodeSeq = bind("discussion_comment",
discussionToHtml(d, level),
"edit" -> {if (User.superUser_?) { editDiscussionButton(d) } else NodeSeq.Empty},
"delete" -> {if (User.superUser_?) { deleteDiscussionButton(d) } else NodeSeq.Empty},
"reply" -> { replyDiscussionButton(d) }
"edit" -> { if (User.validSuperUser_?) editDiscussionButton(d) else NodeSeq.Empty },
"delete" -> { if (User.validSuperUser_?) deleteDiscussionButton(d) else NodeSeq.Empty },
"reply" -> { if (!User.banned_?) replyDiscussionButton(d) else NodeSeq.Empty }
)

/** Render add comment button. */
Expand Down Expand Up @@ -357,7 +357,7 @@ class Template(tpl: DocTemplateEntity) extends tools.nsc.doc.html.page.Template(
{contentComments map (d => contentToHtmlWithActions(d))}
</ul>
{
if (User.loggedIn_?)
if (User.loggedIn_? && !User.banned_?)
contentCommentAddButton
else
contentCommentAddButtonForAnonymous
Expand Down Expand Up @@ -393,8 +393,8 @@ class Template(tpl: DocTemplateEntity) extends tools.nsc.doc.html.page.Template(

/** Render content comment with actions. */
private def contentToHtmlWithActions(d: Content) = bind("content_comment", contentToHtml(d),
"edit" -> {if (User.superUser_?) { editContentButton(d) } else NodeSeq.Empty},
"delete" -> {if (User.superUser_?) { deleteContentButton(d) } else NodeSeq.Empty}
"edit" -> {if (User.validSuperUser_?) { editContentButton(d) } else NodeSeq.Empty},
"delete" -> {if (User.validSuperUser_?) { deleteContentButton(d) } else NodeSeq.Empty}
)

/** Render add comment button. */
Expand Down Expand Up @@ -567,12 +567,12 @@ class Template(tpl: DocTemplateEntity) extends tools.nsc.doc.html.page.Template(
private def controls(mbr: MemberEntity, isSelf: Boolean) =
<div class="controls">
{ select(mbr, isSelf) }
{ if (User.loggedIn_?)
{ if (User.validSuperUser_?)
edit(mbr, isSelf)
}
{ if (User.superUser_?) delete(mbr, isSelf) }
{ if (User.superUser_?) selectDefault(mbr, isSelf) }
{ if (User.superUser_?) propagateToPredecessors(mbr, isSelf) }
{ if (User.validSuperUser_?) delete(mbr, isSelf) }
{ if (User.validSuperUser_?) selectDefault(mbr, isSelf) }
{ if (User.validSuperUser_?) propagateToPredecessors(mbr, isSelf) }
{ export(mbr, isSelf) }
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ProfileOps {
def public_?(): Boolean = {
if (!User.loggedIn_?)
return true
if (User.superUser_?)
if (User.validSuperUser_?)
return false
User.currentUser match {
case Full(u) =>
Expand Down
5 changes: 3 additions & 2 deletions src/main/webapp/scripts/cosettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ $(document).ready(function() {
$("#userlist").jqGrid({
url:'grid/users?',
datatype: "xml",
colNames:['Username', 'Superuser', 'Deleted'],
colNames:['Username', 'Superuser', 'Deleted', 'Banned'],
colModel:[
{name: 'profile', index: 'profile'},
{name: 'superuser', index: 'superuser', width: 60},
{name: 'delete', index: 'delete', width: 60}
{name: 'delete', index: 'delete', width: 60},
{name: 'banned', index: 'banned', width: 60}
],
rowList:[5,10,20,30],
pager: '#userpager',
Expand Down

0 comments on commit a5cf377

Please sign in to comment.