Skip to content

Commit 7cdb4ed

Browse files
committed
fix tricky behaviour with personal dynamic endpoints. /my dynamic
entitity endpoints now return records created by user_id even if not via /my endpoints (i.e. if created with another endpoint that requires a role, the record is still yours)
1 parent 7a1436c commit 7cdb4ed

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

obp-api/src/main/scala/code/dynamicEntity/MapppedDynamicDataProvider.scala

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ import net.liftweb.mapper._
1212
import net.liftweb.util.Helpers.tryo
1313
import org.apache.commons.lang3.StringUtils
1414

15+
/**
16+
* Note on IsPersonalEntity flag:
17+
* The IsPersonalEntity flag indicates HOW a record was created (via /my/ endpoint or not),
18+
* but is NOT used as a filter when querying personal data. The /my/ endpoints return all
19+
* records belonging to the current user (filtered by UserId), regardless of IsPersonalEntity value.
20+
* This provides a unified view of a user's data whether it was created via /my/ or non-/my/ endpoints.
21+
*/
1522
object MappedDynamicDataProvider extends DynamicDataProvider with CustomJsonFormats{
1623
override def save(bankId: Option[String], entityName: String, requestBody: JObject, userId: Option[String], isPersonalEntity: Boolean): Box[DynamicDataT] = {
1724
val idName = getIdName(entityName)
@@ -40,7 +47,7 @@ object MappedDynamicDataProvider extends DynamicDataProvider with CustomJsonForm
4047
if(bankId.isEmpty && !isPersonalEntity ){ //isPersonalEntity == false, get all the data, no need for specific userId.
4148
//forced the empty also to a error here. this is get Dynamic by Id, if it return Empty, better show the error in this level.
4249
DynamicData.find(
43-
By(DynamicData.DynamicDataId, id),
50+
By(DynamicData.DynamicDataId, id),
4451
By(DynamicData.DynamicEntityName, entityName),
4552
By(DynamicData.UserId, userId.getOrElse(null)),
4653
By(DynamicData.IsPersonalEntity, false),
@@ -49,12 +56,11 @@ object MappedDynamicDataProvider extends DynamicDataProvider with CustomJsonForm
4956
case Full(dynamicData) => Full(dynamicData)
5057
case _ => Failure(s"$DynamicDataNotFound dynamicEntityName=$entityName, dynamicDataId=$id")
5158
}
52-
} else if(bankId.isEmpty && isPersonalEntity){ //isPersonalEntity == true, get all the data for specific userId.
59+
} else if(bankId.isEmpty && isPersonalEntity){ //isPersonalEntity == true, get the data for specific userId (regardless of how it was created).
5360
DynamicData.find(
54-
By(DynamicData.DynamicDataId, id),
61+
By(DynamicData.DynamicDataId, id),
5562
By(DynamicData.DynamicEntityName, entityName),
5663
By(DynamicData.UserId, userId.getOrElse(null)),
57-
By(DynamicData.IsPersonalEntity, true),
5864
NullRef(DynamicData.BankId)
5965
) match {
6066
case Full(dynamicData) => Full(dynamicData)
@@ -63,27 +69,26 @@ object MappedDynamicDataProvider extends DynamicDataProvider with CustomJsonForm
6369
} else if(bankId.isDefined && !isPersonalEntity ){ //isPersonalEntity == false, get all the data, no need for specific userId.
6470
//forced the empty also to a error here. this is get Dynamic by Id, if it return Empty, better show the error in this level.
6571
DynamicData.find(
66-
By(DynamicData.DynamicDataId, id),
72+
By(DynamicData.DynamicDataId, id),
6773
By(DynamicData.DynamicEntityName, entityName),
6874
By(DynamicData.IsPersonalEntity, false),
6975
By(DynamicData.BankId, bankId.get),
7076
) match {
7177
case Full(dynamicData) => Full(dynamicData)
7278
case _ => Failure(s"$DynamicDataNotFound dynamicEntityName=$entityName, dynamicDataId=$id, bankId= ${bankId.get}")
7379
}
74-
}else{ //isPersonalEntity == true, get all the data for specific userId.
80+
}else{ //isPersonalEntity == true, get the data for specific userId (regardless of how it was created).
7581
DynamicData.find(
76-
By(DynamicData.DynamicDataId, id),
82+
By(DynamicData.DynamicDataId, id),
7783
By(DynamicData.DynamicEntityName, entityName),
7884
By(DynamicData.BankId, bankId.get),
79-
By(DynamicData.UserId, userId.get),
80-
By(DynamicData.IsPersonalEntity, true)
85+
By(DynamicData.UserId, userId.get)
8186
) match {
8287
case Full(dynamicData) => Full(dynamicData)
8388
case _ => Failure(s"$DynamicDataNotFound dynamicEntityName=$entityName, dynamicDataId=$id, bankId= ${bankId.get}, userId = ${userId.get}")
8489
}
8590
}
86-
91+
8792
}
8893

8994
override def getAllDataJson(bankId: Option[String], entityName: String, userId: Option[String], isPersonalEntity: Boolean): List[JObject] = {
@@ -98,26 +103,24 @@ object MappedDynamicDataProvider extends DynamicDataProvider with CustomJsonForm
98103
By(DynamicData.DynamicEntityName, entityName),
99104
By(DynamicData.IsPersonalEntity, false),
100105
NullRef(DynamicData.BankId),
101-
)
102-
} else if(bankId.isEmpty && isPersonalEntity){ //isPersonalEntity == true, get all the data for specific userId.
106+
)
107+
} else if(bankId.isEmpty && isPersonalEntity){ //isPersonalEntity == true, get all the data for specific userId (regardless of how it was created).
103108
DynamicData.findAll(
104109
By(DynamicData.DynamicEntityName, entityName),
105110
By(DynamicData.UserId, userId.getOrElse(null)),
106-
By(DynamicData.IsPersonalEntity, true),
107111
NullRef(DynamicData.BankId)
108-
)
112+
)
109113
} else if(bankId.isDefined && !isPersonalEntity){ //isPersonalEntity == false, get all the data, no need for specific userId.
110114
DynamicData.findAll(
111115
By(DynamicData.DynamicEntityName, entityName),
112116
By(DynamicData.IsPersonalEntity, false),
113117
By(DynamicData.BankId, bankId.get),
114118
)
115119
}else{
116-
DynamicData.findAll(//isPersonalEntity == true, get all the data for specific userId.
120+
DynamicData.findAll(//isPersonalEntity == true, get all the data for specific userId (regardless of how it was created).
117121
By(DynamicData.DynamicEntityName, entityName),
118122
By(DynamicData.BankId, bankId.get),
119-
By(DynamicData.UserId, userId.getOrElse(null)),
120-
By(DynamicData.IsPersonalEntity, true)
123+
By(DynamicData.UserId, userId.getOrElse(null))
121124
)
122125
}
123126
}
@@ -139,18 +142,16 @@ object MappedDynamicDataProvider extends DynamicDataProvider with CustomJsonForm
139142
By(DynamicData.BankId, bankId.get),
140143
By(DynamicData.IsPersonalEntity, false)
141144
).nonEmpty
142-
} else if(bankId.isEmpty && isPersonalEntity){ //isPersonalEntity == true, get all the data for specific userId.
145+
} else if(bankId.isEmpty && isPersonalEntity){ //isPersonalEntity == true, check if data exists for specific userId (regardless of how it was created).
143146
DynamicData.find(
144147
By(DynamicData.DynamicEntityName, dynamicEntityName),
145148
NullRef(DynamicData.BankId),
146-
By(DynamicData.IsPersonalEntity, true),
147149
By(DynamicData.UserId, userId.getOrElse(null))
148150
).nonEmpty
149-
} else {
151+
} else { //isPersonalEntity == true, check if data exists for specific userId (regardless of how it was created).
150152
DynamicData.find(
151153
By(DynamicData.DynamicEntityName, dynamicEntityName),
152154
By(DynamicData.BankId, bankId.get),
153-
By(DynamicData.IsPersonalEntity, true),
154155
By(DynamicData.UserId, userId.getOrElse(null))
155156
).nonEmpty
156157
}

0 commit comments

Comments
 (0)