- 
                Notifications
    You must be signed in to change notification settings 
- Fork 17
Add [auth|security]:checkRights #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            28 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c7546c3
              
                Add [auth|security]:checkRights
              
              
                Yoann-Abbes ed496e5
              
                fix snippets
              
              
                Yoann-Abbes 9422b6d
              
                Update doc/7/controllers/auth/check-rights/index.md
              
              
                Yoann-Abbes d1ec51f
              
                Update doc/7/controllers/auth/check-rights/index.md
              
              
                Yoann-Abbes 5ac5b6e
              
                Update doc/7/controllers/auth/check-rights/index.md
              
              
                Yoann-Abbes 71c3153
              
                Update doc/7/controllers/auth/check-rights/index.md
              
              
                Yoann-Abbes c97b18a
              
                update doc and variables names
              
              
                Yoann-Abbes 25149cf
              
                Update doc/7/controllers/auth/check-rights/snippets/check-rights.js
              
              
                Yoann-Abbes da99751
              
                Update doc/7/controllers/auth/check-rights/index.md
              
              
                Yoann-Abbes 964eef3
              
                Update doc/7/controllers/security/check-rights/index.md
              
              
                Yoann-Abbes f55d5f7
              
                Update doc/7/controllers/security/check-rights/snippets/check-rights.…
              
              
                Yoann-Abbes 6d45dd3
              
                Update doc/7/controllers/security/check-rights/snippets/check-rights.js
              
              
                Yoann-Abbes d050e0f
              
                Update src/controllers/Security.js
              
              
                Yoann-Abbes 4c7bcd4
              
                Update src/controllers/Security.js
              
              
                Yoann-Abbes e42bec1
              
                Update doc/7/controllers/security/check-rights/snippets/check-rights.js
              
              
                Yoann-Abbes 6e81c01
              
                Update doc/7/controllers/security/check-rights/snippets/check-rights.js
              
              
                Yoann-Abbes 2b5d0a7
              
                Update doc/7/controllers/security/check-rights/index.md
              
              
                Yoann-Abbes 6124628
              
                Update doc/7/controllers/auth/check-rights/index.md
              
              
                Yoann-Abbes 93a4fa3
              
                Update doc/7/controllers/auth/check-rights/index.md
              
              
                Yoann-Abbes a477906
              
                Update doc/7/controllers/auth/check-rights/index.md
              
              
                Yoann-Abbes 793abfa
              
                Update doc/7/controllers/security/check-rights/index.md
              
              
                Yoann-Abbes d15ee9d
              
                Update doc/7/controllers/security/check-rights/index.md
              
              
                Yoann-Abbes 570cbe8
              
                Update src/controllers/Auth.ts
              
              
                Yoann-Abbes 0db5baa
              
                Update src/controllers/Security.js
              
              
                Yoann-Abbes 481e0ff
              
                Update src/controllers/Security.js
              
              
                Yoann-Abbes fae481f
              
                requested changes @aschen
              
              
                Yoann-Abbes a8f2ea9
              
                update doc
              
              
                Yoann-Abbes 1e38014
              
                Update src/controllers/Auth.ts
              
              
                Aschen File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --- | ||
| code: true | ||
| type: page | ||
| title: checkRights | ||
| description: Checks if an API action can be executed by the current user | ||
| --- | ||
|  | ||
| # checkRights | ||
|  | ||
| <SinceBadge version="Kuzzle 2.8.0"/> | ||
| <SinceBadge version="auto-version"/> | ||
|  | ||
| Checks if the provided API request can be executed by the current logged user. | ||
|  | ||
| --- | ||
|  | ||
| ```js | ||
| checkRights(requestPayload) | ||
| ``` | ||
|  | ||
| | Property | Type | Description | | ||
| |--- |--- |--- | | ||
| | `requestPayload` | <pre>object</pre> | Contains a [RequestPayload](/core/2/api/payloads/request) | | ||
|  | ||
| ## `requestPayload` | ||
|  | ||
| The [RequestPayload](/core/2/api/payloads/request) must contains at least the following properties: | ||
|  | ||
| - `controller`: API controller | ||
| - `action`: API action | ||
|  | ||
| --- | ||
|  | ||
| ## Resolves | ||
|  | ||
| A boolean telling whether the provided request would have been allowed or not. | ||
|  | ||
| ## Usage | ||
|  | ||
| <<< ./snippets/check-rights.js | ||
        
          
          
            19 changes: 19 additions & 0 deletions
          
          19 
        
  doc/7/controllers/auth/check-rights/snippets/check-rights.js
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| const requestPayload = { | ||
| controller: 'document', | ||
| action: 'create', | ||
| index: 'nyc-open-data', | ||
| collection: 'yellow-taxi', | ||
| body: { | ||
| name: 'Melis' | ||
| } | ||
| } | ||
|  | ||
| try { | ||
| const result = await kuzzle.auth.checkRights(requestPayload); | ||
| console.log(result); | ||
| /* | ||
| true | ||
| */ | ||
| } catch (error) { | ||
| console.error(error.message); | ||
| } | 
        
          
          
            7 changes: 7 additions & 0 deletions
          
          7 
        
  doc/7/controllers/auth/check-rights/snippets/check-rights.test.yml
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| name: auth#checkRights | ||
| description: Checks if an API action can be executed by the current user | ||
| hooks: | ||
| before: curl -X POST kuzzle:7512/users/foo/_create -H "Content-Type:application/json" --data '{"content":{"profileIds":["default"]},"credentials":{"local":{"username":"foo","password":"bar"}}}' | ||
| after: curl -X DELETE kuzzle:7512/users/foo | ||
| template: default | ||
| expected: true | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --- | ||
| code: true | ||
| type: page | ||
| title: checkRights | ||
|         
                  Yoann-Abbes marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| description: Checks if an API action can be executed by a user | ||
| --- | ||
|  | ||
| # checkRights | ||
|  | ||
| <SinceBadge version="2.8.0"/> | ||
| <SinceBadge version="auto-version"/> | ||
| Checks if the provided API request can be executed by a user. | ||
|  | ||
| --- | ||
|  | ||
| ```js | ||
| checkRights(kuid, requestPayload) | ||
| ``` | ||
|  | ||
| | Property | Type | Description | | ||
| |--- |--- |--- | | ||
| | `kuid` | <pre>string</pre> | User [kuid](/core/2/guides/main-concepts/authentication#kuzzle-user-identifier-kuid) | | ||
| | `requestPayload` | <pre>object</pre> | Contains a [RequestPayload](/core/2/api/payloads/request) | | ||
|  | ||
| ## `requestPayload` | ||
|  | ||
| The [RequestPayload](/core/2/api/payloads/request) must contains at least the following properties: | ||
|  | ||
| - `controller`: API controller | ||
| - `action`: API action | ||
|  | ||
| --- | ||
|  | ||
| ## Resolves | ||
|  | ||
| A boolean telling whether the provided request would have been allowed or not | ||
|  | ||
| ## Usage | ||
|  | ||
| <<< ./snippets/check-rights.js | ||
        
          
          
            19 changes: 19 additions & 0 deletions
          
          19 
        
  doc/7/controllers/security/check-rights/snippets/check-rights.js
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| const requestPayload = { | ||
| controller: 'document', | ||
| action: 'create', | ||
| index: 'nyc-open-data', | ||
| collection: 'yellow-taxi', | ||
| body: { | ||
| name: 'Melis' | ||
| } | ||
| } | ||
|  | ||
| try { | ||
| const allowed = await kuzzle.security.checkRights('foo', requestPayload); | ||
| console.log(allowed); | ||
| /* | ||
| true | ||
| */ | ||
| } catch (error) { | ||
| console.error(error.message); | ||
| } | 
        
          
          
            7 changes: 7 additions & 0 deletions
          
          7 
        
  doc/7/controllers/security/check-rights/snippets/check-rights.test.yml
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| name: security#checkRights | ||
| description: Checks if an API action can be executed by a user | ||
| hooks: | ||
| before: curl -X POST kuzzle:7512/users/foo/_create -H "Content-Type:application/json" --data '{"content":{"profileIds":["default"]},"credentials":{"local":{"username":"foo","password":"bar"}}}' | ||
| after: curl -X DELETE kuzzle:7512/users/foo | ||
| template: default | ||
| expected: true | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.