def clear_notifications(read: bool, user: User, type: str = None): """ Clear a user's notifications; optionally of a specific type. Requires the ``notifications_modify`` permission. Clearing another user's notifications requires the ``notifications_modify_others`` permission. .. :quickref: Notification; View notifications of a type. **Example response**: .. parsed-literal:: { "status": "success", "response": "All notifications cleared." } :>json str response: Response message :statuscode 200: Successfully cleared notifications. :statuscode 403: User does not have permission to clear notifications. """ if not read: raise APIException('You cannot set all notifications to unread.') Notification.update_many( pks=Notification.get_pks_from_type(user.id, type, include_read=False), update={'read': True}, ) Notification.clear_cache_keys(user.id) return flask.jsonify( f'{"All" if not type else type} notifications cleared.')