Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 14b3399

Browse files
Checking the keychain for the correct user
1 parent af14cf7 commit 14b3399

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ class ProjectWindowInterface : AssetPostprocessor
1818
private static List<GitLock> locks = new List<GitLock>();
1919
private static List<string> guids = new List<string>();
2020
private static List<string> guidsLocks = new List<string>();
21+
private static string loggedInUser;
2122

2223
private static IApplicationManager manager;
2324
private static bool isBusy = false;
2425
private static ILogging logger;
2526
private static ILogging Logger { get { return logger = logger ?? LogHelper.GetLogger<ProjectWindowInterface>(); } }
2627
private static CacheUpdateEvent lastRepositoryStatusChangedEvent;
2728
private static CacheUpdateEvent lastLocksChangedEvent;
29+
private static CacheUpdateEvent lastUserChangedEvent;
2830
private static IRepository Repository { get { return manager != null ? manager.Environment.Repository : null; } }
31+
private static IPlatform Platform { get { return manager != null ? manager.Platform : null; } }
2932
private static bool IsInitialized { get { return Repository != null; } }
3033

3134
public static void Initialize(IApplicationManager theManager)
@@ -35,6 +38,9 @@ public static void Initialize(IApplicationManager theManager)
3538

3639
manager = theManager;
3740

41+
Platform.Keychain.ConnectionsChanged += KeychainMayHaveChanged;
42+
KeychainMayHaveChanged();
43+
3844
if (IsInitialized)
3945
{
4046
Repository.StatusEntriesChanged += RepositoryOnStatusEntriesChanged;
@@ -83,6 +89,11 @@ private static void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent)
8389
}
8490
}
8591

92+
private static void KeychainMayHaveChanged()
93+
{
94+
loggedInUser = Platform.Keychain.Connections.Select(x => x.Username).FirstOrDefault();
95+
}
96+
8697
[MenuItem(AssetsMenuRequestLock, true, 10000)]
8798
private static bool ContextMenu_CanLock()
8899
{
@@ -104,7 +115,7 @@ private static bool ContextMenu_CanUnlock()
104115
return false;
105116
if (isBusy)
106117
return false;
107-
return Selection.objects.Any(IsObjectLocked);
118+
return Selection.objects.Any(f => IsObjectLocked(f , true));
108119
}
109120

110121
[MenuItem(AssetsMenuReleaseLockForced, true, 10002)]
@@ -180,14 +191,20 @@ private static bool IsObjectUnlocked(Object selected)
180191
}
181192

182193
private static bool IsObjectLocked(Object selected)
194+
{
195+
return IsObjectLocked(selected, false);
196+
}
197+
198+
private static bool IsObjectLocked(Object selected, bool isLockedByCurrentUser)
183199
{
184200
if (selected == null)
185201
return false;
186202

187203
NPath assetPath = AssetDatabase.GetAssetPath(selected.GetInstanceID()).ToNPath();
188204
NPath repositoryPath = manager.Environment.GetRepositoryPath(assetPath);
189205

190-
return locks.Any(x => repositoryPath == x.Path);
206+
var isObjectLocked = locks.Any(x => repositoryPath == x.Path && (!isLockedByCurrentUser || x.Owner.Name == loggedInUser));
207+
return isObjectLocked;
191208
}
192209

193210
private static ITask CreateUnlockObjectTask(Object selected, bool force)

0 commit comments

Comments
 (0)