From 14b3399e5bf7529140cc8f9bbbaeb8137e1250f1 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 28 Nov 2018 08:30:51 -0500 Subject: [PATCH 1/2] Checking the keychain for the correct user --- .../GitHub.Unity/UI/ProjectWindowInterface.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs index 0d4f21182..a5da9e81b 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs @@ -18,6 +18,7 @@ class ProjectWindowInterface : AssetPostprocessor private static List locks = new List(); private static List guids = new List(); private static List guidsLocks = new List(); + private static string loggedInUser; private static IApplicationManager manager; private static bool isBusy = false; @@ -25,7 +26,9 @@ class ProjectWindowInterface : AssetPostprocessor private static ILogging Logger { get { return logger = logger ?? LogHelper.GetLogger(); } } private static CacheUpdateEvent lastRepositoryStatusChangedEvent; private static CacheUpdateEvent lastLocksChangedEvent; + private static CacheUpdateEvent lastUserChangedEvent; private static IRepository Repository { get { return manager != null ? manager.Environment.Repository : null; } } + private static IPlatform Platform { get { return manager != null ? manager.Platform : null; } } private static bool IsInitialized { get { return Repository != null; } } public static void Initialize(IApplicationManager theManager) @@ -35,6 +38,9 @@ public static void Initialize(IApplicationManager theManager) manager = theManager; + Platform.Keychain.ConnectionsChanged += KeychainMayHaveChanged; + KeychainMayHaveChanged(); + if (IsInitialized) { Repository.StatusEntriesChanged += RepositoryOnStatusEntriesChanged; @@ -83,6 +89,11 @@ private static void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent) } } + private static void KeychainMayHaveChanged() + { + loggedInUser = Platform.Keychain.Connections.Select(x => x.Username).FirstOrDefault(); + } + [MenuItem(AssetsMenuRequestLock, true, 10000)] private static bool ContextMenu_CanLock() { @@ -104,7 +115,7 @@ private static bool ContextMenu_CanUnlock() return false; if (isBusy) return false; - return Selection.objects.Any(IsObjectLocked); + return Selection.objects.Any(f => IsObjectLocked(f , true)); } [MenuItem(AssetsMenuReleaseLockForced, true, 10002)] @@ -180,6 +191,11 @@ private static bool IsObjectUnlocked(Object selected) } private static bool IsObjectLocked(Object selected) + { + return IsObjectLocked(selected, false); + } + + private static bool IsObjectLocked(Object selected, bool isLockedByCurrentUser) { if (selected == null) return false; @@ -187,7 +203,8 @@ private static bool IsObjectLocked(Object selected) NPath assetPath = AssetDatabase.GetAssetPath(selected.GetInstanceID()).ToNPath(); NPath repositoryPath = manager.Environment.GetRepositoryPath(assetPath); - return locks.Any(x => repositoryPath == x.Path); + var isObjectLocked = locks.Any(x => repositoryPath == x.Path && (!isLockedByCurrentUser || x.Owner.Name == loggedInUser)); + return isObjectLocked; } private static ITask CreateUnlockObjectTask(Object selected, bool force) From eefd2fd3a22225fce2085fdc1a68868f47229c9f Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 28 Nov 2018 08:31:44 -0500 Subject: [PATCH 2/2] Cleanup --- .../Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs index a5da9e81b..97cbc521e 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs @@ -26,7 +26,6 @@ class ProjectWindowInterface : AssetPostprocessor private static ILogging Logger { get { return logger = logger ?? LogHelper.GetLogger(); } } private static CacheUpdateEvent lastRepositoryStatusChangedEvent; private static CacheUpdateEvent lastLocksChangedEvent; - private static CacheUpdateEvent lastUserChangedEvent; private static IRepository Repository { get { return manager != null ? manager.Environment.Repository : null; } } private static IPlatform Platform { get { return manager != null ? manager.Platform : null; } } private static bool IsInitialized { get { return Repository != null; } } @@ -203,8 +202,7 @@ private static bool IsObjectLocked(Object selected, bool isLockedByCurrentUser) NPath assetPath = AssetDatabase.GetAssetPath(selected.GetInstanceID()).ToNPath(); NPath repositoryPath = manager.Environment.GetRepositoryPath(assetPath); - var isObjectLocked = locks.Any(x => repositoryPath == x.Path && (!isLockedByCurrentUser || x.Owner.Name == loggedInUser)); - return isObjectLocked; + return locks.Any(x => repositoryPath == x.Path && (!isLockedByCurrentUser || x.Owner.Name == loggedInUser)); } private static ITask CreateUnlockObjectTask(Object selected, bool force)