Changeset 1222


Ignore:
Timestamp:
Nov 30, 2010, 2:10:42 PM (13 years ago)
Author:
robert@…
Message:

Implemented improved authorisation to give administrators all permissions (ticket #207)

Location:
trunk/grails-app
Files:
7 edited

Legend:

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

    r1199 r1222  
    256256                        if(study) {
    257257                                // Check whether the person is allowed to read the data of this study
    258                                 /*
    259258                                if( !study.canRead(AuthenticationService.getRemotelyLoggedInUser( params.consumer, params.token ))) {
    260259                                        response.sendError(401)
    261260                                        return false
    262261                                }
    263                                 */
    264262
    265263                                def assays = []
     
    283281
    284282                                assays.each{ assay ->
    285                                         if (assay.module.url.equals(params.consumer )) {
     283                                        if (assay.module.url.equals(params.consumer)) {
    286284                                                if(assay) {
    287285                                                        def map = [:]
  • trunk/grails-app/controllers/dbnp/exporter/ExporterController.groovy

    r1220 r1222  
    4545        def c = dbnp.studycapturing.Study.createCriteria()
    4646
    47         def studies
    48         if( user == null ) {
    49             studies = c.list {
    50                 maxResults(max)
    51                 and {
    52                     eq( "published", true )
    53                     eq( "publicstudy", true )
    54                 }
    55             }
    56         } else {
    57             studies = c.list {
    58                 maxResults(max)
    59                 or {
    60                     eq( "owner", user )
    61                     writers {
    62                         eq( "id", user.id )
    63                     }
    64                     and {
    65                         readers {
    66                             eq( "id", user.id )
    67                         }
    68                         eq( "published", true )
    69                     }
    70                 }
    71             }
    72         }
     47        def studies = Study.giveReadableStudies(user, max);
    7348        [studyInstanceList: studies, studyInstanceTotal: studies.count()]
    7449    }
  • trunk/grails-app/controllers/dbnp/studycapturing/StudyController.groovy

    r1213 r1222  
    33import grails.converters.*
    44import grails.plugins.springsecurity.Secured
    5 
    65
    76/**
     
    2524        def max = Math.min(params.max ? params.int('max') : 10, 100)
    2625
    27         def c = Study.createCriteria()
    28 
    29         def studies
    30         if( user == null ) {
    31             studies = c.list {
    32                 maxResults(max)
    33                 and {
    34                     eq( "published", true )
    35                     eq( "publicstudy", true )
    36                 }
    37             }
    38         } else {
    39             studies = c.list {
    40                 maxResults(max)
    41                 or {
    42                     eq( "owner", user )
    43                     writers {
    44                         eq( "id", user.id )
    45                     }
    46                     and {
    47                         readers {
    48                             eq( "id", user.id )
    49                         }
    50                         eq( "published", true )
    51                     }
    52                 }
    53             }
    54         }
    55        
     26        def studies = Study.giveReadableStudies( user, max );
     27
    5628        [studyInstanceList: studies, studyInstanceTotal: studies.count(), loggedInUser: user]
    5729    }
  • trunk/grails-app/controllers/nmc/PilotController.groovy

    r1204 r1222  
    1616
    1717import dbnp.studycapturing.*;
     18import grails.plugins.springsecurity.Secured
     19
    1820
    1921class PilotController {
     
    3739   }
    3840       
    39     def index = {
     41    @Secured(['IS_AUTHENTICATED_REMEMBERED'])
     42        def index = {
    4043               
    4144                session.pilot = true
    42                
     45
    4346                def user = authenticationService.getLoggedInUser()
    4447                def max = Math.min(params.max ? params.int('max') : 10, 100)
    45 
    46                 def c = Study.createCriteria()
    47 
    48                 def studies
    49                 if( user == null ) {
    50                         //login and return here...
    51                         redirect(controller:"login", action:"auth")
    52                         return false
    53                        
    54                 } else {
    55                         studies = c.list {
    56                                 maxResults(max)
    57                                 or {
    58                                         eq( "owner", user )
    59                                         writers {
    60                                                 eq( "id", user.id )
    61                                         }
    62                                         and {
    63                                                 readers {
    64                                                         eq( "id", user.id )
    65                                                 }
    66                                                 eq( "published", true )
    67                                         }
    68                                 }
    69                         }
    70                 }
     48                def studies = Study.giveReadableStudies(user, max);
    7149               
    7250                def studyInstance = new Study()
  • trunk/grails-app/domain/dbnp/authentication/SecRole.groovy

    r1159 r1222  
    11package dbnp.authentication
    22
    3 class SecRole {
     3class SecRole implements Serializable {
    44
    55        String authority
  • trunk/grails-app/domain/dbnp/studycapturing/Study.groovy

    r1036 r1222  
    410410        }
    411411
     412                // Administrators are allowed to read every study
     413                if( loggedInUser.hasAdminRights() ) {
     414                        return true;
     415                }
     416
    412417        // Owners and writers are allowed to read this study
    413418        if( this.owner == loggedInUser || this.writers.contains(loggedInUser) ) {
     
    430435            return false;
    431436        }
     437
     438                // Administrators are allowed to write every study
     439                if( loggedInUser.hasAdminRights() ) {
     440                        return true;
     441                }
     442
    432443        return this.owner == loggedInUser || this.writers.contains(loggedInUser)
    433444    }
     
    443454    }
    444455
     456        /**
     457         * Returns a list of studies that are writable for the given user
     458         */
     459        public static giveWritableStudies(SecUser user, int max) {
     460                // User that are not logged in, are not allowed to write to a study
     461                if( user == null )
     462                        return [];
     463                       
     464                def c = Study.createCriteria()
     465
     466                // Administrators are allowed to read everything
     467                if( user.hasAdminRights() ) {
     468                        return c.list {
     469                                maxResults(max)
     470                        }
     471                }
     472
     473                return c.list {
     474                        maxResults(max)
     475                        or {
     476                                eq( "owner", user )
     477                                writers {
     478                                        eq( "id", user.id )
     479                                }
     480                        }
     481                }
     482        }
     483
     484        /**
     485         * Returns a list of studies that are readable by the given user
     486         */
     487        public static giveReadableStudies(SecUser user, int max) {
     488                def c = Study.createCriteria()
     489
     490        // Administrators are allowed to read everything
     491                if( user == null ) {
     492            return c.list {
     493                                maxResults(max)
     494                and {
     495                    eq( "published", true )
     496                    eq( "publicstudy", true )
     497                }
     498            }
     499        } else if( user.hasAdminRights() ) {
     500            return c.list {
     501                                maxResults(max)
     502                        }
     503                } else  {
     504            return c.list {
     505                                maxResults(max)
     506                or {
     507                    eq( "owner", user )
     508                    writers {
     509                        eq( "id", user.id )
     510                    }
     511                    and {
     512                        readers {
     513                            eq( "id", user.id )
     514                        }
     515                        eq( "published", true )
     516                    }
     517                }
     518            }
     519        }
     520        }
    445521}
  • trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy

    r1206 r1222  
    653653         */
    654654        def studySelect = { attrs ->
    655                 // Find all studies the user has access to
    656                 def user = AuthenticationService.getLoggedInUser()
    657 
    658                 def c = Study.createCriteria()
    659                 attrs.from = c.list {
    660                     or {
    661                         eq( "owner", user )
    662                         writers {
    663                             eq( "id", user.id )
    664                         }
    665                     }
    666                 }
     655                // Find all studies the user has access to (max 100)
     656                attrs.from = Study.giveWritableStudies(AuthenticationService.getLoggedInUser(), 100);
    667657
    668658                // got a name?
Note: See TracChangeset for help on using the changeset viewer.