Skip to content
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

[Device Manager] Render security recommendations (PSG-681) #6965

Merged
merged 17 commits into from
Sep 5, 2022

Conversation

onurays
Copy link
Contributor

@onurays onurays commented Aug 30, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Implement current session section as in the new layout.

Motivation and context

Closes #6964

Screenshots / GIFs

security_recommendations

Tests

  • Enable the new device management feature flag
  • Go to "Security & Privacy" settings
  • Press the "Show all sessions (V2, WIP)" entry
  • See the security recommendations are rendered as in the new layout

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@onurays onurays linked an issue Aug 30, 2022 that may be closed by this pull request
@onurays onurays changed the base branch from develop to feature/ons/device_manager_other_session_list August 30, 2022 13:40
@onurays onurays requested review from a team and bmarty and removed request for a team August 30, 2022 14:22
Base automatically changed from feature/ons/device_manager_other_session_list to develop August 31, 2022 14:01
@onurays onurays marked this pull request as ready for review August 31, 2022 14:06
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just small remarks. Did not test the code.

fun execute(lastSeenTs: Long): Boolean {
val lastSeenDate = DateProvider.toLocalDateTime(lastSeenTs)
val currentDate = DateProvider.currentLocalDateTime()
val diffMilliseconds = currentDate.toTimestamp() - lastSeenDate.toTimestamp()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would inject a Clock in the constructor and just make a diff between lastSeenTs and clock.epochMillis().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, easier, done.

<string name="device_manager_unverified_sessions_title">Unverified sessions</string>
<string name="device_manager_unverified_sessions_description">Verify or sign out from unverified sessions.</string>
<string name="device_manager_inactive_sessions_title">Inactive sessions</string>
<string name="device_manager_inactive_sessions_description">Consider signing out from old sessions (90 days or older) you don’t use anymore.</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a word missing here?

Suggested change
<string name="device_manager_inactive_sessions_description">Consider signing out from old sessions (90 days or older) you don’t use anymore.</string>
<string name="device_manager_inactive_sessions_description">Consider signing out from old sessions (90 days or older) you don’t use them anymore.</string>

Also maybe 90 days or more is better than 90 days or older.

Disclaimer: I am not a native speaker!

Also 90 is hard-coded here, we could use %d and use SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS for more flexibility (Element or their forks).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I believe the missing word was "that".

@onurays onurays requested a review from bmarty August 31, 2022 17:21
@@ -3222,6 +3222,7 @@
<string name="device_manager_other_sessions_view_all">View All (%1$d)</string>
<string name="device_manager_other_sessions_description_verified">Verified · Last activity %1$s</string>
<string name="device_manager_other_sessions_description_unverified">Unverified · Last activity %1$s</string>
<string name="device_manager_other_sessions_description_inactive">Inactive for %1$d+ days (%2$s)</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ElementBot is right (I did not think about it) please use a plurals. In English it will not change anything (since I do not think we will use the value 1, but on some other languages we can have difference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5791a4d

@@ -3228,6 +3228,6 @@
<string name="device_manager_unverified_sessions_title">Unverified sessions</string>
<string name="device_manager_unverified_sessions_description">Verify or sign out from unverified sessions.</string>
<string name="device_manager_inactive_sessions_title">Inactive sessions</string>
<string name="device_manager_inactive_sessions_description">Consider signing out from old sessions (90 days or older) you don’t use anymore.</string>
<string name="device_manager_inactive_sessions_description">Consider signing out from old sessions (%1$d days or more) that you don’t use anymore.</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also use a plurals here. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5791a4d

@@ -42,18 +44,26 @@ class OtherSessionsController @Inject constructor(
} else {
data.take(NUMBER_OF_OTHER_DEVICES_TO_RENDER).forEach { device ->
val formattedLastActivityDate = host.dateFormatter.format(device.deviceInfo.lastSeenTs, DateFormatKind.DEFAULT_DATE_AND_TIME)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To format the date when inactive, I think we should use DateFormatKind.TIMELINE_DAY_DIVIDER to only get the date.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fbff8d6

views.recommendationShieldImageView.backgroundTintList = ColorStateList.valueOf(backgroundTint)
}

fun setTitle(title: String) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create a dedicated SecurityRecommendationViewState in a separate file to encapsulate all data used to render the view. Then we would have a unique method render(viewState: SecurityRecommendationViewState) to be called when needed.

Copy link
Contributor

@mnaturel mnaturel Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ViewState added in c53a8f3

@@ -68,6 +72,7 @@ abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.la
holder.otherSessionVerificationStatusImageView.render(roomEncryptionTrustLevel)
holder.otherSessionNameTextView.text = sessionName
holder.otherSessionDescriptionTextView.text = sessionDescription
holder.otherSessionDescriptionTextView.setCompoundDrawablesWithIntrinsicBounds(sessionDescriptionDrawable, null, null, null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure the drawable will have the same tint color as the text. Can you check both in light and dark mode?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in dc0a36

@mnaturel mnaturel force-pushed the feature/ons/device_manager_security_recommendations branch from 287c153 to 9dc0a36 Compare September 2, 2022 14:16
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 2, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@mnaturel mnaturel merged commit e81f02f into develop Sep 5, 2022
@mnaturel mnaturel deleted the feature/ons/device_manager_security_recommendations branch September 5, 2022 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Device Manager] Render Security Recommendations
3 participants