From 31d89c37fe3479be5f933b0ae84eb71c3aa279b0 Mon Sep 17 00:00:00 2001 From: enahum Date: Mon, 13 Mar 2017 13:39:35 -0300 Subject: [PATCH] PLT-5506 Record user agent/device type in the active sessions list (#342) * Add user info and userAgent * notice --- NOTICE.txt | 31 +++++++++++++++++++ android/app/build.gradle | 1 + .../java/com/mattermost/MainApplication.java | 2 ++ android/settings.gradle | 2 ++ app/components/root/root.js | 4 +++ ios/Mattermost.xcodeproj/project.pbxproj | 8 ++++- package.json | 1 + service/client/client.js | 10 ++++++ 8 files changed, 58 insertions(+), 1 deletion(-) diff --git a/NOTICE.txt b/NOTICE.txt index e03f8bebd..b9cc921e6 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -801,3 +801,34 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --- + +## react-native-device-info + +This product contains 'react-native-device-info', library to provide a device information to react native on both iOS and Android. + +* HOMEPAGE + * https://github.com/rebeccahughes/react-native-device-info + +* LICENSE: + +The MIT License (MIT) + +Copyright (c) 2015 Rebecca Hughes + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/android/app/build.gradle b/android/app/build.gradle index 62b3a66c8..064ec7e80 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -147,6 +147,7 @@ dependencies { compile ('com.google.android.gms:play-services-gcm:9.0.0') { force = true; } + compile project(':react-native-device-info') compile project(':react-native-cookies') compile project(':react-native-vector-icons') compile project(':react-native-svg') diff --git a/android/app/src/main/java/com/mattermost/MainApplication.java b/android/app/src/main/java/com/mattermost/MainApplication.java index f37c04780..267ad2d11 100644 --- a/android/app/src/main/java/com/mattermost/MainApplication.java +++ b/android/app/src/main/java/com/mattermost/MainApplication.java @@ -4,6 +4,7 @@ import android.app.Application; import android.util.Log; import com.facebook.react.ReactApplication; +import com.learnium.RNDeviceInfo.RNDeviceInfo; import com.psykar.cookiemanager.CookieManagerPackage; import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage; import com.oblador.vectoricons.VectorIconsPackage; @@ -29,6 +30,7 @@ public class MainApplication extends Application implements ReactApplication { protected List getPackages() { return Arrays.asList( new MainReactPackage(), + new RNDeviceInfo(), new CookieManagerPackage(), new ReactNativePushNotificationPackage(), new VectorIconsPackage(), diff --git a/android/settings.gradle b/android/settings.gradle index c57483643..da3881f72 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,4 +1,6 @@ rootProject.name = 'Mattermost' +include ':react-native-device-info' +project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android') include ':react-native-cookies' project(':react-native-cookies').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cookies/android') include ':react-native-push-notification' diff --git a/app/components/root/root.js b/app/components/root/root.js index ce719c179..e8f57e32b 100644 --- a/app/components/root/root.js +++ b/app/components/root/root.js @@ -4,8 +4,11 @@ import React, {PropTypes, PureComponent} from 'react'; import {AppState, View} from 'react-native'; import {IntlProvider} from 'react-intl'; +import DeviceInfo from 'react-native-device-info'; + import PushNotification from 'app/components/push_notification'; +import Client from 'service/client'; import {Constants} from 'service/constants'; import {getTranslations} from 'service/i18n'; import EventEmitter from 'service/utils/event_emitter'; @@ -34,6 +37,7 @@ export default class Root extends PureComponent { componentDidMount() { AppState.addEventListener('change', this.handleAppStateChange); EventEmitter.on(Constants.CONFIG_CHANGED, this.handleConfigChanged); + Client.setUserAgent(DeviceInfo.getUserAgent()); } componentWillUnmount() { diff --git a/ios/Mattermost.xcodeproj/project.pbxproj b/ios/Mattermost.xcodeproj/project.pbxproj index 8bf828b42..9319f5915 100644 --- a/ios/Mattermost.xcodeproj/project.pbxproj +++ b/ios/Mattermost.xcodeproj/project.pbxproj @@ -5,7 +5,6 @@ }; objectVersion = 46; objects = { - /* Begin PBXBuildFile section */ 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; }; 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; }; @@ -39,6 +38,7 @@ C035DB50ED2045F09923FFAE /* MaterialCommunityIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 04AA5E8EF3B54735A11E3B95 /* MaterialCommunityIcons.ttf */; }; C337E8708D2845C6A8DBB47E /* Ionicons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 2DCFD31D3F4A4154822AB532 /* Ionicons.ttf */; }; F006936FC2884C24A1321FC0 /* MaterialIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 356C9186FA374641A00EB2EA /* MaterialIcons.ttf */; }; + 10CD747CE4304BD6AB38B4CD /* libRNDeviceInfo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EE671DF7637347CD8C069819 /* libRNDeviceInfo.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -308,6 +308,8 @@ EDC04CBCF81642219D199CBB /* Octicons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Octicons.ttf; path = "../node_modules/react-native-vector-icons/Fonts/Octicons.ttf"; sourceTree = ""; }; F1F071EE85494E269A50AE88 /* SimpleLineIcons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = SimpleLineIcons.ttf; path = "../node_modules/react-native-vector-icons/Fonts/SimpleLineIcons.ttf"; sourceTree = ""; }; F81F6DC42D394831B4549928 /* libRNSearchBar.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNSearchBar.a; sourceTree = ""; }; + B97AA6F961BB47D3A3297E8E /* RNDeviceInfo.xcodeproj */ = {isa = PBXFileReference; name = "RNDeviceInfo.xcodeproj"; path = "../node_modules/react-native-device-info/RNDeviceInfo.xcodeproj"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; }; + EE671DF7637347CD8C069819 /* libRNDeviceInfo.a */ = {isa = PBXFileReference; name = "libRNDeviceInfo.a"; path = "libRNDeviceInfo.a"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -339,6 +341,7 @@ 7F63D2841E6C9585001FAE12 /* libRCTPushNotification.a in Frameworks */, B50561A109B4442299F82327 /* libRNSearchBar.a in Frameworks */, 9906AC672C594EEB9D5EE503 /* libRNCookieManagerIOS.a in Frameworks */, + 10CD747CE4304BD6AB38B4CD /* libRNDeviceInfo.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -546,6 +549,7 @@ 2B25899FDAC149EB96ED3305 /* RNVectorIcons.xcodeproj */, 59954D479A89488091EB588F /* RNSearchBar.xcodeproj */, 31A0780E2F224AC8AF8E6930 /* RNCookieManagerIOS.xcodeproj */, + B97AA6F961BB47D3A3297E8E /* RNDeviceInfo.xcodeproj */, ); name = Libraries; sourceTree = ""; @@ -1050,6 +1054,7 @@ LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1068,6 +1073,7 @@ LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/package.json b/package.json index 08b624a29..1fd9d3075 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "react-native": "0.40.0", "react-native-button": "1.7.1", "react-native-cookies": "2.0.0", + "react-native-device-info": "0.10.1", "react-native-drawer": "2.3.0", "react-native-keyboard-aware-scroll-view": "0.2.7", "react-native-keyboard-spacer": "0.3.1", diff --git a/service/client/client.js b/service/client/client.js index 4f3f92129..9095fc73b 100644 --- a/service/client/client.js +++ b/service/client/client.js @@ -11,6 +11,7 @@ const HEADER_BEARER = 'BEARER'; const HEADER_REQUESTED_WITH = 'X-Requested-With'; const HEADER_TOKEN = 'Token'; const HEADER_X_VERSION_ID = 'X-Version-Id'; +const HEADER_USER_AGENT = 'User-Agent'; export default class Client { constructor() { @@ -19,6 +20,7 @@ export default class Client { this.url = ''; this.urlVersion = '/api/v3'; this.serverVersion = ''; + this.userAgent = null; this.translations = { connectionError: 'There appears to be a problem with your internet connection.', @@ -34,6 +36,10 @@ export default class Client { this.url = url; } + setUserAgent(userAgent) { + this.userAgent = userAgent; + } + getToken() { return this.token; } @@ -135,6 +141,10 @@ export default class Client { headers[HEADER_AUTH] = `${HEADER_BEARER} ${this.token}`; } + if (this.userAgent) { + headers[HEADER_USER_AGENT] = this.userAgent; + } + if (options.headers) { Object.assign(headers, options.headers); }