comparison sat/plugins/plugin_misc_groupblog.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents be6d91572633
children
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
59 59
60 def __init__(self, host): 60 def __init__(self, host):
61 log.info(_("Group blog plugin initialization")) 61 log.info(_("Group blog plugin initialization"))
62 self.host = host 62 self.host = host
63 self._p = self.host.plugins["XEP-0060"] 63 self._p = self.host.plugins["XEP-0060"]
64 host.trigger.add("XEP-0277_item2data", self._item2dataTrigger) 64 host.trigger.add("XEP-0277_item2data", self._item_2_data_trigger)
65 host.trigger.add("XEP-0277_data2entry", self._data2entryTrigger) 65 host.trigger.add("XEP-0277_data2entry", self._data_2_entry_trigger)
66 host.trigger.add("XEP-0277_comments", self._commentsTrigger) 66 host.trigger.add("XEP-0277_comments", self._comments_trigger)
67 67
68 ## plugin management methods ## 68 ## plugin management methods ##
69 69
70 def getHandler(self, client): 70 def get_handler(self, client):
71 return GroupBlog_handler() 71 return GroupBlog_handler()
72 72
73 @defer.inlineCallbacks 73 @defer.inlineCallbacks
74 def profileConnected(self, client): 74 def profile_connected(self, client):
75 try: 75 try:
76 yield self.host.checkFeatures(client, (NS_PUBSUB_GROUPBLOG,)) 76 yield self.host.check_features(client, (NS_PUBSUB_GROUPBLOG,))
77 except exceptions.FeatureNotFound: 77 except exceptions.FeatureNotFound:
78 client.server_groupblog_available = False 78 client.server_groupblog_available = False
79 log.warning( 79 log.warning(
80 _( 80 _(
81 "Server is not able to manage item-access pubsub, we can't use group blog" 81 "Server is not able to manage item-access pubsub, we can't use group blog"
83 ) 83 )
84 else: 84 else:
85 client.server_groupblog_available = True 85 client.server_groupblog_available = True
86 log.info(_("Server can manage group blogs")) 86 log.info(_("Server can manage group blogs"))
87 87
88 def getFeatures(self, profile): 88 def features_get(self, profile):
89 try: 89 try:
90 client = self.host.getClient(profile) 90 client = self.host.get_client(profile)
91 except exceptions.ProfileNotSetError: 91 except exceptions.ProfileNotSetError:
92 return {} 92 return {}
93 try: 93 try:
94 return {"available": C.boolConst(client.server_groupblog_available)} 94 return {"available": C.bool_const(client.server_groupblog_available)}
95 except AttributeError: 95 except AttributeError:
96 if self.host.isConnected(profile): 96 if self.host.is_connected(profile):
97 log.debug("Profile is not connected, service is not checked yet") 97 log.debug("Profile is not connected, service is not checked yet")
98 else: 98 else:
99 log.error("client.server_groupblog_available should be available !") 99 log.error("client.server_groupblog_available should be available !")
100 return {} 100 return {}
101 101
102 def _item2dataTrigger(self, item_elt, entry_elt, microblog_data): 102 def _item_2_data_trigger(self, item_elt, entry_elt, microblog_data):
103 """Parse item to find group permission elements""" 103 """Parse item to find group permission elements"""
104 config_form = data_form.findForm(item_elt, NS_PUBSUB_ITEM_CONFIG) 104 config_form = data_form.findForm(item_elt, NS_PUBSUB_ITEM_CONFIG)
105 if config_form is None: 105 if config_form is None:
106 return 106 return
107 access_model = config_form.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN) 107 access_model = config_form.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN)
108 if access_model == self._p.ACCESS_PUBLISHER_ROSTER: 108 if access_model == self._p.ACCESS_PUBLISHER_ROSTER:
109 opt = self._p.OPT_ROSTER_GROUPS_ALLOWED 109 opt = self._p.OPT_ROSTER_GROUPS_ALLOWED
110 microblog_data['groups'] = config_form.fields[opt].values 110 microblog_data['groups'] = config_form.fields[opt].values
111 111
112 def _data2entryTrigger(self, client, mb_data, entry_elt, item_elt): 112 def _data_2_entry_trigger(self, client, mb_data, entry_elt, item_elt):
113 """Build fine access permission if needed 113 """Build fine access permission if needed
114 114
115 This trigger check if "group*" key are present, 115 This trigger check if "group*" key are present,
116 and create a fine item config to restrict view to these groups 116 and create a fine item config to restrict view to these groups
117 """ 117 """
128 allowed = data_form.Field(None, self._p.OPT_ROSTER_GROUPS_ALLOWED, values=groups) 128 allowed = data_form.Field(None, self._p.OPT_ROSTER_GROUPS_ALLOWED, values=groups)
129 form.addField(access) 129 form.addField(access)
130 form.addField(allowed) 130 form.addField(allowed)
131 item_elt.addChild(form.toElement()) 131 item_elt.addChild(form.toElement())
132 132
133 def _commentsTrigger(self, client, mb_data, options): 133 def _comments_trigger(self, client, mb_data, options):
134 """This method is called when a comments node is about to be created 134 """This method is called when a comments node is about to be created
135 135
136 It changes the access mode to roster if needed, and give the authorized groups 136 It changes the access mode to roster if needed, and give the authorized groups
137 """ 137 """
138 if "group" in mb_data: 138 if "group" in mb_data: