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

Disabling Release Lock when appropriate #968

Merged
merged 2 commits into from
Dec 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ProjectWindowInterface : AssetPostprocessor
private static List<GitLock> locks = new List<GitLock>();
private static List<string> guids = new List<string>();
private static List<string> guidsLocks = new List<string>();
private static string loggedInUser;

private static IApplicationManager manager;
private static bool isBusy = false;
Expand All @@ -26,6 +27,7 @@ class ProjectWindowInterface : AssetPostprocessor
private static CacheUpdateEvent lastRepositoryStatusChangedEvent;
private static CacheUpdateEvent lastLocksChangedEvent;
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)
Expand All @@ -35,6 +37,9 @@ public static void Initialize(IApplicationManager theManager)

manager = theManager;

Platform.Keychain.ConnectionsChanged += KeychainMayHaveChanged;
KeychainMayHaveChanged();

if (IsInitialized)
{
Repository.StatusEntriesChanged += RepositoryOnStatusEntriesChanged;
Expand Down Expand Up @@ -83,6 +88,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()
{
Expand All @@ -104,7 +114,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)]
Expand Down Expand Up @@ -180,14 +190,19 @@ 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;

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

return locks.Any(x => repositoryPath == x.Path);
return locks.Any(x => repositoryPath == x.Path && (!isLockedByCurrentUser || x.Owner.Name == loggedInUser));
}

private static ITask CreateUnlockObjectTask(Object selected, bool force)
Expand Down