-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
CCCT-469 || HQ User Invite Connect #2927
base: connect_qa
Are you sure you want to change the base?
Changes from all commits
763ac95
10d717a
34c179c
44ee961
8a94a0a
a0fa29a
5a745af
d24b72b
28bf471
d219577
0c8f519
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/main" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="org.commcare.activities.connect.HQUserInviteActivity"> | ||
|
||
<ImageView | ||
android:id="@+id/imageView2" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginHorizontal="30dp" | ||
android:adjustViewBounds="true" | ||
android:src="@drawable/commcare_logo" | ||
app:layout_constraintBottom_toTopOf="@+id/guideline3" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" /> | ||
|
||
<org.commcare.views.connect.connecttextview.ConnectMediumTextView | ||
android:id="@+id/tvHqInvitationHeaderTitle" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginHorizontal="30dp" | ||
android:layout_marginTop="20dp" | ||
android:gravity="center" | ||
android:text="" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/imageView2" /> | ||
|
||
<org.commcare.views.connect.RoundedButton | ||
android:id="@+id/btn_accept_invitation" | ||
android:layout_width="match_parent" | ||
android:layout_height="40dp" | ||
android:layout_marginHorizontal="50dp" | ||
android:layout_marginTop="30dp" | ||
android:text="@string/connect_hq_invitation_accept" | ||
android:visibility="visible" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/tvHqInvitationHeaderTitle" | ||
app:roundButtonBackgroundColor="@color/connect_blue_color" | ||
app:roundButtonTextColor="@color/white" | ||
app:roundButtonTextSize="6sp" | ||
tools:text="@string/connect_hq_invitation_accept" /> | ||
|
||
<org.commcare.views.connect.RoundedButton | ||
android:id="@+id/btn_denied_invitation" | ||
android:layout_width="match_parent" | ||
android:layout_height="40dp" | ||
android:layout_marginHorizontal="50dp" | ||
android:layout_marginTop="15dp" | ||
android:text="@string/connect_hq_invitation_denied" | ||
android:visibility="visible" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/btn_accept_invitation" | ||
app:roundButtonBackgroundColor="@color/connect_blue_color" | ||
app:roundButtonTextColor="@color/white" | ||
app:roundButtonTextSize="6sp" | ||
tools:text="@string/connect_hq_invitation_denied" /> | ||
|
||
<org.commcare.views.connect.RoundedButton | ||
android:id="@+id/btn_go_to_recovery" | ||
android:layout_width="match_parent" | ||
android:layout_height="40dp" | ||
android:layout_marginHorizontal="50dp" | ||
android:layout_marginTop="15dp" | ||
android:text="@string/connect_hq_invitation_go_to_recovery" | ||
android:visibility="visible" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/btn_denied_invitation" | ||
app:roundButtonBackgroundColor="@color/connect_blue_color" | ||
app:roundButtonTextColor="@color/white" | ||
app:roundButtonTextSize="6sp" | ||
tools:text="@string/connect_hq_invitation_go_to_recovery" /> | ||
|
||
<org.commcare.views.connect.connecttextview.ConnectMediumTextView | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:text="" | ||
android:id="@+id/connect_phone_verify_error" | ||
android:textSize="16sp" | ||
android:layout_marginTop="10dp" | ||
android:textColor="@color/connect_red" | ||
app:layout_constraintEnd_toEndOf="@+id/btn_denied_invitation" | ||
app:layout_constraintStart_toStartOf="@+id/btn_denied_invitation" | ||
app:layout_constraintTop_toBottomOf="@+id/btn_denied_invitation" /> | ||
|
||
<androidx.constraintlayout.widget.Guideline | ||
android:id="@+id/guideline3" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
app:layout_constraintGuide_percent="0.35" /> | ||
|
||
<ProgressBar | ||
android:id="@+id/progress_bar" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
style="?android:attr/progressBarStyle" | ||
android:layout_centerHorizontal="true" | ||
android:progressTint="@color/connect_blue_color" | ||
android:progressBackgroundTint="@color/connect_blue_color" | ||
android:visibility="gone" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/btn_go_to_recovery" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
package org.commcare.activities.connect; | ||
|
||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import org.commcare.activities.CommCareActivity; | ||
import org.commcare.activities.DispatchActivity; | ||
import org.commcare.android.database.connect.models.ConnectUserRecord; | ||
import org.commcare.connect.ConnectManager; | ||
import org.commcare.connect.network.ApiConnectId; | ||
import org.commcare.connect.network.IApiCallback; | ||
import org.commcare.dalvik.R; | ||
import org.commcare.dalvik.databinding.ActivityHquserInviteBinding; | ||
import org.javarosa.core.io.StreamsUtil; | ||
import org.javarosa.core.services.Logger; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Locale; | ||
|
||
public class HQUserInviteActivity extends CommCareActivity<HQUserInviteActivity> { | ||
|
||
private ActivityHquserInviteBinding binding; | ||
String domain; | ||
String inviteCode; | ||
String username; | ||
String callBackURL; | ||
String connectUserName; | ||
boolean isProgressVisible = false; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
binding = ActivityHquserInviteBinding.inflate(getLayoutInflater()); | ||
setContentView(binding.getRoot()); | ||
Intent intent = getIntent(); | ||
Uri data = intent.getData(); | ||
if (data != null) { | ||
callBackURL = data.getQueryParameter("callback_url"); | ||
username = data.getQueryParameter("hq_username"); | ||
inviteCode = data.getQueryParameter("invite_code"); | ||
domain = data.getQueryParameter("hq_domain"); | ||
connectUserName = data.getQueryParameter("connect_username"); | ||
} | ||
handleButtons(); | ||
} | ||
Comment on lines
+25
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Ensure domain & parameter validation in onCreate() |
||
|
||
private void handleButtons() { | ||
ConnectManager.init(this); | ||
|
||
ConnectUserRecord user = ConnectManager.getUser(this); | ||
boolean isTokenPresent = ConnectManager.isConnectIdConfigured(); | ||
boolean isCorrectUser = true; | ||
if (user != null) { | ||
isCorrectUser = user.getUserId().equals(connectUserName); | ||
} | ||
|
||
if (isCorrectUser) { | ||
binding.tvHqInvitationHeaderTitle.setText(isTokenPresent | ||
? getString(R.string.connect_hq_invitation_heading, username) | ||
: getString(R.string.connect_hq_invitation_connectId_not_configure)); | ||
setButtonVisibility(isTokenPresent); | ||
setButtonListeners(isTokenPresent); | ||
} else { | ||
binding.tvHqInvitationHeaderTitle.setText(getString(R.string.connect_hq_invitation_wrong_user)); | ||
hideInvitationButtons(); | ||
} | ||
} | ||
|
||
private void setButtonVisibility(boolean isTokenPresent) { | ||
binding.btnAcceptInvitation.setVisibility(isTokenPresent ? View.VISIBLE : View.GONE); | ||
binding.btnDeniedInvitation.setVisibility(isTokenPresent ? View.VISIBLE : View.GONE); | ||
binding.btnGoToRecovery.setVisibility(isTokenPresent ? View.GONE : View.VISIBLE); | ||
} | ||
|
||
private void hideInvitationButtons() { | ||
binding.btnAcceptInvitation.setVisibility(View.GONE); | ||
binding.btnDeniedInvitation.setVisibility(View.GONE); | ||
binding.btnGoToRecovery.setVisibility(View.GONE); | ||
} | ||
|
||
private void setButtonListeners(boolean isTokenPresent) { | ||
if (isTokenPresent) { | ||
binding.btnAcceptInvitation.setOnClickListener(view -> handleInvitation(callBackURL, inviteCode)); | ||
binding.btnDeniedInvitation.setOnClickListener(view -> finish()); | ||
} else { | ||
binding.btnGoToRecovery.setOnClickListener(view -> ConnectManager.registerUser(this, success -> { | ||
if (success) { | ||
ConnectManager.goToConnectJobsList(this); | ||
} | ||
}) | ||
); | ||
} | ||
} | ||
|
||
private void handleInvitation(String callBackUrl, String inviteCode) { | ||
IApiCallback callback = new IApiCallback() { | ||
@Override | ||
public void processSuccess(int responseCode, InputStream responseData) { | ||
binding.progressBar.setVisibility(View.GONE); | ||
try { | ||
String responseAsString = new String(StreamsUtil.inputStreamToByteArray(responseData)); | ||
if (responseAsString.length() > 0) { | ||
startActivity(new Intent(HQUserInviteActivity.this, DispatchActivity.class)); | ||
finish(); | ||
} | ||
} catch (IOException e) { | ||
Logger.exception("Parsing return from OTP request", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void processFailure(int responseCode, IOException e) { | ||
binding.progressBar.setVisibility(View.GONE); | ||
String message = ""; | ||
if (responseCode > 0) { | ||
message = String.format(Locale.getDefault(), "(%d)", responseCode); | ||
} else if (e != null) { | ||
message = e.toString(); | ||
} | ||
setErrorMessage("Error requesting SMS code" + message); | ||
} | ||
|
||
@Override | ||
public void processNetworkFailure() { | ||
binding.progressBar.setVisibility(View.GONE); | ||
setErrorMessage(getString(R.string.recovery_network_unavailable)); | ||
} | ||
|
||
@Override | ||
public void processOldApiError() { | ||
binding.progressBar.setVisibility(View.GONE); | ||
setErrorMessage(getString(R.string.recovery_network_outdated)); | ||
} | ||
}; | ||
ConnectUserRecord user = ConnectManager.getUser(this); | ||
binding.progressBar.setVisibility(View.VISIBLE); | ||
boolean isBusy = !ApiConnectId.hqUserInvitation(HQUserInviteActivity.this,user.getUserId(),user.getPassword(), callBackUrl, inviteCode, callback); | ||
if (isBusy) { | ||
Toast.makeText(HQUserInviteActivity.this, R.string.busy_message, Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
Comment on lines
+100
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve error messaging & handle potential null connectIdToken |
||
|
||
public void setErrorMessage(String message) { | ||
if (message == null) { | ||
binding.connectPhoneVerifyError.setVisibility(View.GONE); | ||
} else { | ||
binding.connectPhoneVerifyError.setVisibility(View.VISIBLE); | ||
binding.connectPhoneVerifyError.setText(message); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
binding = null; | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
finish(); | ||
ConnectManager.handleFinishedActivity(this, requestCode, resultCode, data); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Additional security measures recommended for deep link handling
Based on the code analysis, while the activity implements basic deep link handling, several security improvements are needed:
callback_url
parameter, which could lead to potential security vulnerabilitiesRecommended actions:
🔗 Analysis chain
Verify security measures for exported activity handling deep links
The exported activity with deep link handling requires careful security review:
android:autoVerify="true"
is intended as it allows automatic verification of deep links🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 93
Script:
Length of output: 7692
Script:
Length of output: 3910