Changeset 935


Ignore:
Timestamp:
Oct 11, 2010, 12:48:31 PM (13 years ago)
Author:
j.saito@…
Message:

Added dummy REST resource for getAuthorizationLevel.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/RestController.groovy

    r934 r935  
    1818import dbnp.studycapturing.Study
    1919import dbnp.studycapturing.Assay
     20import dbnp.user.User
    2021import grails.converters.*
    2122import nl.metabolomicscentre.dsp.http.BasicAuthentication
     
    3334        def beforeInterceptor = [action:this.&auth,except:["isUser"]]
    3435        def credentials
    35         def requestUser
     36        def requestUser = User.findByName( "user" )
    3637
    3738        /**
     
    4445
    4546            credentials = BasicAuthentication.credentialsFromRequest(request)
    46                 requestUser = authService.authUser(credentials.u,credentials.p)
     47                //requestUser = authService.authUser(credentials.u,credentials.p)
     48                // we circumvene the user
    4749                if(!requestUser) {
    4850                    response.sendError(403)
     
    130132                        def study = Study.find( "from Study as s where s.code=?", [id] )
    131133                        if(study && study.owner == requestUser) study.assays.each{ assay ->
    132                                 //if (assay.module.url.equals(params.moduleURL)) {
     134                                if (assay.module.url.equals(params.moduleURL)) {
    133135                                def map = ['name':assay.name, 'assayToken':assay.getToken()]
    134136                                        assays.push( map )
    135                                 //}
     137                                }
    136138                        }
    137139                }
     
    275277        }
    276278
    277         /**
     279   /**
    278280        * REST resource for dbNP modules.
    279281        *
     
    283285        *
    284286        * Example REST call (without authentication):
    285         * http://localhost:8080/gscf/rest/getStudy/study?studyToken=PPSH
    286         *
     287    *   http://localhost:8080/gscf/rest/getStudy/study?studyToken=PPSH
     288    *
    287289        * Returns the JSON object:
    288290        * {"title":"NuGO PPS human study","studyToken":"PPSH","startDate":"2008-01-13T23:00:00Z",
     
    299301        render items as JSON*/
    300302        }
     303
     304
     305
     306
     307
     308   /**
     309        * REST resource for dbNP modules.
     310        *
     311        * @param studyToken String, the external identifier of the study
     312        *
     313        * Dummy for testing only. (Warning: to be replaced as soon as the authorization is implemented!)
     314        * @param Hash with exactly the values that will be returned
     315        *
     316        * @return Hash with keys 'isReader', 'isEditor', 'isOwner' }
     317        */
     318
     319        def getAuthorizationLevel = {
     320
     321                isReader = false
     322                isEditor = false
     323                isOwner  = false
     324
     325                // Warning: this case is only for testing!
     326                // The code below should be used until the
     327                // authorization works.
     328                if( params.isOwner || params.isEditor || params.Owner ) {
     329                        return render ['isReader':params.isOwner,
     330                                'isEditor':params.isEditor, 'isOwner':params.isOwner] as JSON
     331                }
     332
     333
     334                // in future the users authorization level will be based on authorization model
     335                /*
     336                if( params.studyToken ) {
     337                        def id = params.studyToken
     338                        def study = Study.find( "from Study as s where s.code=?", [id])
     339                        if(study) study.subjects.each { subjects.push it.name }
     340                }
     341
     342                def user
     343                if( params.user ) {
     344                        def id = params.user
     345                        user = users.find( "from User as u where u.code=?", [id])
     346                }
     347
     348                if( study.readers.contains(user) ) isReader = true
     349                if( study.editors.contains(user) ) isEditor = true
     350                if( study.owner.contains(user) )   isOwner  = true
     351
     352                */
     353
     354                render ['isReader':isOwner, 'isEditor':isEditor, 'isOwner':isOwner] as JSON
     355    }
     356
     357
    301358}
Note: See TracChangeset for help on using the changeset viewer.