@@ -36,6 +36,7 @@ def __init__(self, client):
3636 self .user_service = self .client ['SoftLayer_User_Customer' ]
3737 self .override_service = self .client ['Network_Service_Vpn_Overrides' ]
3838 self .account_service = self .client ['SoftLayer_Account' ]
39+ self .subscription_service = self .client ['SoftLayer_Email_Subscription' ]
3940 self .resolvers = [self ._get_id_from_username ]
4041 self .all_permissions = None
4142
@@ -85,6 +86,52 @@ def get_all_permissions(self):
8586 self .all_permissions = sorted (permissions , key = itemgetter ('keyName' ))
8687 return self .all_permissions
8788
89+ def get_all_notifications (self ):
90+ """Calls SoftLayer_Email_Subscription::getAllObjects
91+
92+ Stores the result in self.all_permissions
93+ :returns: A list of dictionaries that contains all valid permissions
94+ """
95+ return self .subscription_service .getAllObjects (mask = 'mask[enabled]' )
96+
97+ def enable_notifications (self , notifications_names ):
98+ """Enables a list of notifications for the current a user profile.
99+
100+ :param list notifications_names: List of notifications names to enable
101+ :returns: True on success
102+
103+ Example::
104+ enable_notifications(['Order Approved','Reload Complete'])
105+ """
106+
107+ result = False
108+ notifications = self .gather_notifications (notifications_names )
109+ for notification in notifications :
110+ notification_id = notification .get ('id' )
111+ result = self .subscription_service .enable (id = notification_id )
112+ if not result :
113+ return False
114+ return result
115+
116+ def disable_notifications (self , notifications_names ):
117+ """Disable a list of notifications for the current a user profile.
118+
119+ :param list notifications_names: List of notifications names to disable
120+ :returns: True on success
121+
122+ Example::
123+ disable_notifications(['Order Approved','Reload Complete'])
124+ """
125+
126+ result = False
127+ notifications = self .gather_notifications (notifications_names )
128+ for notification in notifications :
129+ notification_id = notification .get ('id' )
130+ result = self .subscription_service .disable (id = notification_id )
131+ if not result :
132+ return False
133+ return result
134+
88135 def add_permissions (self , user_id , permissions ):
89136 """Enables a list of permissions for a user
90137
@@ -237,6 +284,23 @@ def format_permission_object(self, permissions):
237284 raise exceptions .SoftLayerError ("'%s' is not a valid permission" % permission )
238285 return pretty_permissions
239286
287+ def gather_notifications (self , notifications_names ):
288+ """Gets a list of notifications.
289+
290+ :param list notifications_names: A list of notifications names.
291+ :returns: list of notifications.
292+ """
293+ notifications = []
294+ available_notifications = self .get_all_notifications ()
295+ for notification in notifications_names :
296+ result = next ((item for item in available_notifications
297+ if item .get ('name' ) == notification ), None )
298+ if result :
299+ notifications .append (result )
300+ else :
301+ raise exceptions .SoftLayerError ("{} is not a valid notification name" .format (notification ))
302+ return notifications
303+
240304 def create_user (self , user_object , password ):
241305 """Blindly sends user_object to SoftLayer_User_Customer::createObject
242306
0 commit comments