<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: SAP CAP User in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437934#M4657635</link>
    <description>&lt;P&gt;Hi Mateo,&lt;/P&gt;&lt;P&gt;This is a typical use case for restrict annotations: &lt;A href="https://cap.cloud.sap/docs/guides/authorization#restrict-annotation" target="test_blank"&gt;https://cap.cloud.sap/docs/guides/authorization#restrict-annotation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
    <pubDate>Fri, 10 Sep 2021 09:08:45 GMT</pubDate>
    <dc:creator>david_kunz2</dc:creator>
    <dc:date>2021-09-10T09:08:45Z</dc:date>
    <item>
      <title>SAP CAP User</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaq-p/12437926</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;
  &lt;P&gt;We have an entity as follows:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;@assert.unique: {
  favourite: [user, useCasePatternInstance]
}
@description : 'User favourites reference architectures'
entity useCasePatternInstancesFavourites : managed, cuid {

    @mandatory user: String(200)
    @description: 'Application user';

    @mandatory useCasePatternInstance: Association to UseCasePatternInstances
    @description: 'Favoured use case pattern instance';

}
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Where user is the user logged in the app consuming the ODATA service.&lt;/P&gt;
  &lt;P&gt;Instead of passing the user in the URL (for READ operations) or in the payload (for WRITE operations), is there any elegant to manage this with any kind of annotation where those details are retrieved automatically from the JWT token?&lt;/P&gt;
  &lt;P&gt;Many thanks!&lt;/P&gt;
  &lt;P&gt;C.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 14:56:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaq-p/12437926</guid>
      <dc:creator>Cristian</dc:creator>
      <dc:date>2021-09-08T14:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CAP User</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437927#M4657628</link>
      <description>&lt;P&gt;Hi Mateo,&lt;/P&gt;&lt;P&gt;I'm not entirely sure what you want to achieve. Your fields are database fields which must be filled by you.&lt;BR /&gt;We support e.g. @cds.on.update:$user to fill it automatically.&lt;BR /&gt;&lt;A href="https://cap.cloud.sap/docs/guides/domain-models#using-predefined-named-aspects" target="test_blank"&gt;https://cap.cloud.sap/docs/guides/domain-models#using-predefined-named-aspects&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You can also have a look at restrict annotations: &lt;A href="https://cap.cloud.sap/docs/guides/authorization#restrict-annotation" target="test_blank"&gt;https://cap.cloud.sap/docs/guides/authorization#restrict-annotation&lt;/A&gt;&lt;BR /&gt;Maybe that is something you want to do.&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;David&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Sep 2021 08:20:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437927#M4657628</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2021-09-09T08:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CAP User</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437928#M4657629</link>
      <description>&lt;P&gt;Many thanks  &lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;I have added the annotations for insert and update as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;@assert.unique: {
  favourite: [user, useCasePatternInstance]
}
@description : 'User favourites reference architectures'
entity useCasePatternInstancesFavourites : managed, cuid {

    @mandatory user: String(200) 
    @cds.on.insert : $user @cds.on.update : $user
    @description: 'Application user';

    @mandatory useCasePatternInstance: Association to UseCasePatternInstances
    @description: 'Favoured use case pattern instance';

}
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But when executing the calls I am getting the error as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;{
    "error": {
        "code": "400",
        "message": "Value is required",
        "target": "user",
        "@Common.numericSeverity": 4
    }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The service is assigned to a custom role with @requires annotation and the retrieval of the token and further consumption of the service is working fine.&lt;/P&gt;&lt;P&gt;Any idea what may be going on?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;C.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Sep 2021 15:05:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437928#M4657629</guid>
      <dc:creator>Cristian</dc:creator>
      <dc:date>2021-09-09T15:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CAP User</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437929#M4657630</link>
      <description>&lt;P&gt; @&lt;SPAN class="mention-scrubbed"&gt;int_suite_test57&lt;/SPAN&gt;, May be you should get rid of @mandatory for the 'user' since it is automatically updated with @cds.on.insert.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 05:46:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437929#M4657630</guid>
      <dc:creator>kammaje_cis</dc:creator>
      <dc:date>2021-09-10T05:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CAP User</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437930#M4657631</link>
      <description>&lt;P&gt;Exactly,  @mandatory is used for external input validation.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 06:20:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437930#M4657631</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2021-09-10T06:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CAP User</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437931#M4657632</link>
      <description>&lt;P&gt;Many thanks both  &lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt; and &lt;SPAN class="mention-scrubbed"&gt;kkammaje_cis&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;That sorted the issue. Now last question, how can I ensure that when a user makes a request to get the favourites as follows:&lt;/P&gt;&lt;P&gt;GET /useCasePatternInstancesFavourites&lt;/P&gt;&lt;P&gt;The API just responds with the entries where user = $user. Is there any way to do that with annotations or needs to be done programmatically in a handler?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;C.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 07:19:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437931#M4657632</guid>
      <dc:creator>Cristian</dc:creator>
      <dc:date>2021-09-10T07:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CAP User</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437932#M4657633</link>
      <description>&lt;P&gt;Hi Mateo,&lt;/P&gt;&lt;P&gt;I'm not sure how you model favorites in terms of user properties, or what you exactly want to achieve. Could you clarify?&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 07:28:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437932#M4657633</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2021-09-10T07:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CAP User</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437933#M4657634</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;Many thanks for your response.&lt;/P&gt;&lt;P&gt;We have an entity name useCasePatternInstances and the useCasePatternInstancesFavourites detailed above. At UI level, users can add to favourites several useCasePatternInstances, hence the relationship.&lt;/P&gt;&lt;P&gt;Then, users can see all their favourites and for that a GET request needs to be triggered. It is there when we want to ensure that the API just replies favourites for the user logged in. ODATA wise is very easy with the below request (user = email account):&lt;/P&gt;&lt;P&gt;GET /useCasePatternInstances?$filter=user eq 'myemail@gmail.com'&lt;/P&gt;&lt;P&gt;But we want to avoid this and instead or hardcoding this in the URL we are exploring using annotations where this information is retrieved from the JWT token as it is happening in the insert and update operations with the cds annotations. This as well will reduce risks of users seen favourites of other users due to the fact that if you are clever enough you can execute F12 and in Google Tools you change the email of the request :).&lt;/P&gt;&lt;P&gt;Hope it is clear.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;M.  &lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 07:43:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437933#M4657634</guid>
      <dc:creator>Cristian</dc:creator>
      <dc:date>2021-09-10T07:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CAP User</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437934#M4657635</link>
      <description>&lt;P&gt;Hi Mateo,&lt;/P&gt;&lt;P&gt;This is a typical use case for restrict annotations: &lt;A href="https://cap.cloud.sap/docs/guides/authorization#restrict-annotation" target="test_blank"&gt;https://cap.cloud.sap/docs/guides/authorization#restrict-annotation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 09:08:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437934#M4657635</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2021-09-10T09:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CAP User</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437935#M4657636</link>
      <description>&lt;P&gt;As David mentioned. restrict annotation is one way. Another way can be to build it into the entity definition of the service itself.&lt;/P&gt;&lt;P&gt;At the time of defining the entity for the &lt;EM&gt;service&lt;/EM&gt;, you can just do&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Entity useCasePatternInstances as projection from &amp;lt;database table&amp;gt; where user = $user&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Sep 2021 09:47:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cap-user/qaa-p/12437935#M4657636</guid>
      <dc:creator>kammaje_cis</dc:creator>
      <dc:date>2021-09-10T09:47:08Z</dc:date>
    </item>
  </channel>
</rss>

