Skip to content

Commit

Permalink
Merge pull request #147 from DimensionSrl/feature/updates
Browse files Browse the repository at this point in the history
Added private emails to user access control check
  • Loading branch information
dulvui authored Feb 29, 2024
2 parents fd5c090 + a88b241 commit 4a888c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface CommunityApiService {
@Header("Authorization") accessToken: String
): AccountsResponse

@GET("contacts?@p1='noi_contactcat_placepresscommunity'&@p2=['181640000']&\$select=emailaddress1,firstname,lastname,fullname,_parentcustomerid_value&\$filter=Microsoft.Dynamics.CRM.ContainValues(PropertyName%3D@p1,PropertyValues%3D@p2)%20and%20statuscode%20eq%201&\$count=true&\$orderby=fullname")
@GET("contacts?@p1='noi_contactcat_placepresscommunity'&@p2=['181640000']&\$select=emailaddress1,emailaddress2,emailaddress3,firstname,lastname,fullname,_parentcustomerid_value&\$filter=Microsoft.Dynamics.CRM.ContainValues(PropertyName%3D@p1,PropertyValues%3D@p2)%20and%20statuscode%20eq%201&\$count=true&\$orderby=fullname")
suspend fun getContacts(
@Header("Authorization") accessToken: String
): ContactResponse
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/it/bz/noi/community/data/models/Contact.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ data class Contact(
val fullName: String,
@SerializedName("emailaddress1")
val email: String?,
@SerializedName("emailaddress2")
val email2: String?,
@SerializedName("emailaddress3")
val email3: String?,
@SerializedName("_parentcustomerid_value")
val accountId: String?,
@SerializedName("companyName")
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/it/bz/noi/community/oauth/AuthManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import it.bz.noi.community.R
import it.bz.noi.community.data.api.CommunityApiService
import it.bz.noi.community.data.api.RetrofitBuilder
import it.bz.noi.community.data.api.bearer
import it.bz.noi.community.data.models.Contact
import it.bz.noi.community.storage.removeAccessGranted
import it.bz.noi.community.storage.removeAuthState
import it.bz.noi.community.storage.getAccessGranted
Expand Down Expand Up @@ -94,14 +95,14 @@ object AuthManager {
}

val contacts = RetrofitBuilder.communityApiService.getContacts(token.bearer()).contacts
contacts.firstOrNull {
it.email == mail
} != null
contacts.any { it.matches(mail) }
} catch (ex: Exception) {
false
}
}

private fun Contact.matches(mail: String): Boolean = mail == email || mail == email2 || mail == email3

private suspend fun UserState.toStatus(): AuthStateStatus {
return when {
authState.authorizationException != null -> AuthStateStatus.Error(
Expand Down

0 comments on commit 4a888c0

Please sign in to comment.