Skip to content

Commit

Permalink
#24 remove user role definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Sep 6, 2017
1 parent 1b0373b commit 2e889b7
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 84 deletions.
4 changes: 2 additions & 2 deletions app/org/elastic4play/controllers/Authenticated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AuthenticatedRequest[A](val authContext: AuthContext, request: Request[A])
def userId: String = authContext.userId
def userName: String = authContext.userName
def requestId: String = Instance.getRequestId(request)
def roles: Seq[Role.Type] = authContext.roles
def roles: Seq[Role] = authContext.roles
}

sealed trait ExpirationStatus
Expand Down Expand Up @@ -208,7 +208,7 @@ class Authenticated(
* If user has sufficient right (have required role) action is executed
* otherwise, action returns a not authorized error
*/
def apply(requiredRole: Role.Type) = new ActionBuilder[AuthenticatedRequest, AnyContent] {
def apply(requiredRole: Role) = new ActionBuilder[AuthenticatedRequest, AnyContent] {
val executionContext: ExecutionContext = ec

def parser: BodyParser[AnyContent] = defaultParser
Expand Down
72 changes: 0 additions & 72 deletions app/org/elastic4play/controllers/DBListCtrl.scala

This file was deleted.

2 changes: 1 addition & 1 deletion app/org/elastic4play/services/FindSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import akka.stream.scaladsl.Source
import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.searches.RichSearchHit
import com.sksamuel.elastic4s.searches.aggs.{ AggregationDefinition, KeyedFiltersAggregationDefinition, RichAggregations }
import com.sksamuel.elastic4s.searches.queries.{ BuildableTermsQueryImplicits, ParentIdQueryDefinition, QueryDefinition }
import com.sksamuel.elastic4s.searches.queries.{ BuildableTermsQueryImplicits, QueryDefinition }
import org.apache.lucene.search.join.ScoreMode
import org.elasticsearch.search.aggregations.bucket.filter.Filter
import org.elasticsearch.search.aggregations.bucket.filters.Filters
Expand Down
2 changes: 1 addition & 1 deletion app/org/elastic4play/services/JsonFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object JsonFormat {

implicit val attachmentFormat: OFormat[Attachment] = OFormat(attachmentReads, attachmentWrites)

implicit val roleFormat: Format[Role.Type] = enumFormat(Role)
implicit val roleWrites: Writes[Role] = Writes[Role](role JsString(role.name))

implicit def configWrites: OWrites[Configuration] = OWrites { (cfg: Configuration)
JsObject(cfg.subKeys.map(key key configValueWrites.writes(cfg.underlying.getValue(key))).toSeq)
Expand Down
11 changes: 3 additions & 8 deletions app/org/elastic4play/services/UserSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ import scala.concurrent.Future
import play.api.libs.json.JsObject
import play.api.mvc.RequestHeader

import org.elastic4play.models.HiveEnumeration

object Role extends Enumeration with HiveEnumeration {
type Type = Value
val read, write, admin = Value
}
abstract class Role(val name: String)

trait AuthContext {
def userId: String
def userName: String
def requestId: String
def roles: Seq[Role.Type]
def roles: Seq[Role]
private val baseAudit = new AtomicBoolean(true)
def getBaseAudit: Boolean = baseAudit.get && baseAudit.getAndSet(false)
}
Expand All @@ -35,7 +30,7 @@ trait User {
val attributes: JsObject
val id: String
def getUserName: String
def getRoles: Seq[Role.Type]
def getRoles: Seq[Role]
}

object AuthCapability extends Enumeration {
Expand Down

0 comments on commit 2e889b7

Please sign in to comment.