Implement more of warnings/alerts for pending updates

This commit is contained in:
Greg Neagle
2014-02-27 13:51:26 -08:00
parent ee99e86be1
commit e8c43f9ad7
3 changed files with 72 additions and 16 deletions
@@ -103,6 +103,24 @@ class AlertController(NSObject):
elif btn_pressed == self._force_warning_ok_btn:
msulog.log("user", "dismissed_forced_logout_warning")
def alertToExtraUpdates(self):
alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
NSLocalizedString(u"Additional Pending Updates", u'AdditionalPendingUpdatesText'),
NSLocalizedString(u"OK", u'OKButtonText'),
nil,
nil,
NSLocalizedString(
(u"There are additional pending updates to install or remove."),
u'AdditionalPendingUpdatesDetail'))
self._currentAlert = alert
alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
self.window, self, self.extraUpdatesAlertDidEnd_returnCode_contextInfo_, nil)
@AppHelper.endSheetMethod
def extraUpdatesAlertDidEnd_returnCode_contextInfo_(
self, alert, returncode, contextinfo):
self._currentAlert = None
def confirmUpdatesAndInstall(self):
if self.alertedToMultipleUsers():
return
@@ -48,6 +48,7 @@ class MSUMainWindowController(NSWindowController):
_current_page_filename = None
stop_requested = False
user_warned_about_extra_updates = False
html_dir = None
@@ -112,6 +113,7 @@ class MSUMainWindowController(NSWindowController):
def loadInitialView(self):
if MunkiItems.getEffectiveUpdateList():
self._alertedUserToOutstandingUpdates = True
self.loadUpdatesPage_(self)
else:
self.loadAllSoftwarePage_(self)
@@ -321,8 +323,15 @@ class MSUMainWindowController(NSWindowController):
else:
NSApp.delegate().managedsoftwareupdate_task = "checktheninstall"
NSApp.delegate().statusController.startMunkiStatusSession()
elif not self._alertedUserToOutstandingUpdates and MunkiItems.updatesContainNonOptionalItems():
# current list of updates contains some not explicitly chosen by the user
self.loadUpdatesPage_(self)
self._alertedUserToOutstandingUpdates = True
self.alert_controller.alertToExtraUpdates()
return
else:
NSLog('selfService choices unchanged')
self._alertedUserToOutstandingUpdates = False
self.kickOffUpdateSession()
def getUpdateCount(self):
@@ -667,6 +676,7 @@ class MSUMainWindowController(NSWindowController):
self.updateDOMforOptionalItem(item)
if item['status'] in ['will-be-installed', 'update-will-be-installed', 'will-be-removed']:
self._alertedUserToOutstandingUpdates = False
if not self._update_in_progress:
self.updateNow()
else:
@@ -128,13 +128,35 @@ def updatesRequireRestart():
if 'Restart' in item.get('RestartAction', '')]) > 0
def updatesContainNonOptionalItems():
'''Does the list of updates contain items not selected by the user?'''
if not munki.munkiUpdatesContainAppleItems() and getAppleUpdates():
# available Apple updates are not user selected
return True
install_info = getInstallInfo()
install_items = install_info.get('managed_installs', [])
#NSLog('install_items: %s' % install_items)
removal_items = install_info.get('removals', [])
#NSLog('removal_items: %s' % removal_items)
filtered_installs = [item for item in install_items
if item['name'] not in SelfService().installs()]
#NSLog('filtered_installs: %s' % filtered_installs)
if filtered_installs:
return True
filtered_uninstalls = [item for item in removal_items
if item['name'] not in SelfService().uninstalls()]
#NSLog('filtered_uninstalls: %s' % filtered_uninstalls)
if filtered_uninstalls:
return True
return False
def getEffectiveUpdateList():
'''Combine the updates Munki has found with any optional choices to
make the effective list of updates'''
update_list = getUpdateList()
managed_update_names = getInstallInfo().get('managed_updates', [])
optional_item_names = [item['name'] for item in getOptionalInstallItems()]
self_service_uninstalls = munki.readSelfServiceManifest().get('managed_uninstalls', [])
self_service_uninstalls = SelfService().uninstalls()
# items in the update_list that are part of optional_items
# could have their installation state changed; so filter those out
filtered_updates = [item for item in getUpdateList()
@@ -175,8 +197,8 @@ def allOptionalChoicesProcessed():
def getMyItemsList():
'''Returns a list of optional_installs items the user has chosen
to install or to remove'''
self_service_installs = munki.readSelfServiceManifest().get('managed_installs', [])
self_service_uninstalls = munki.readSelfServiceManifest().get('managed_uninstalls', [])
self_service_installs = SelfService().installs()
self_service_uninstalls = SelfService().uninstalls()
item_list = [item for item in getOptionalInstallItems()
if item['name'] in self_service_installs]
items_to_remove = [item for item in getOptionalInstallItems()
@@ -189,30 +211,36 @@ def getMyItemsList():
class SelfService(object):
'''An object to wrap interactions with the SelfServiceManifest'''
def __init__(self):
self.self_service_installs = set(
self._installs = set(
munki.readSelfServiceManifest().get('managed_installs', []))
self.self_service_uninstalls = set(
self._uninstalls = set(
munki.readSelfServiceManifest().get('managed_uninstalls', []))
def installs(self):
return list(self._installs)
def uninstalls(self):
return list(self._uninstalls)
def subscribe(self, item):
self.self_service_installs.add(item['name'])
self.self_service_uninstalls.discard(item['name'])
self._installs.add(item['name'])
self._uninstalls.discard(item['name'])
self._save_self_service_choices()
def unsubscribe(self, item):
self.self_service_installs.discard(item['name'])
self.self_service_uninstalls.add(item['name'])
self._installs.discard(item['name'])
self._uninstalls.add(item['name'])
self._save_self_service_choices()
def unmanage(self, item):
self.self_service_installs.discard(item['name'])
self.self_service_uninstalls.discard(item['name'])
self._installs.discard(item['name'])
self._uninstalls.discard(item['name'])
self._save_self_service_choices()
def _save_self_service_choices(self):
current_choices = {}
current_choices['managed_installs'] = list(self.self_service_installs)
current_choices['managed_uninstalls'] = list(self.self_service_uninstalls)
current_choices['managed_installs'] = list(self._installs)
current_choices['managed_uninstalls'] = list(self._uninstalls)
munki.writeSelfServiceManifest(current_choices)
@@ -505,8 +533,8 @@ class OptionalItem(GenericItem):
def _get_status(self):
'''Calculates initial status for an item'''
managed_update_names = getInstallInfo().get('managed_updates', [])
self_service_installs = SelfService().self_service_installs
self_service_uninstalls = SelfService().self_service_uninstalls
self_service_installs = SelfService().installs()
self_service_uninstalls = SelfService().uninstalls()
if self.get('installed'):
if self['name'] in self_service_uninstalls:
status = 'will-be-removed'