Skip to content

Commit 36e7026

Browse files
committed
[FEATURE][auth] Add support to Plugin Manager
1 parent 487be23 commit 36e7026

File tree

4 files changed

+184
-98
lines changed

4 files changed

+184
-98
lines changed

python/pyplugin_installer/installer.py

+5
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ def addRepository(self):
427427
reposName = reposName + "(2)"
428428
# add to settings
429429
settings.setValue(reposName + "/url", reposURL)
430+
settings.setValue(reposName + "/authcfg", dlg.editAuthCfg.text().strip())
430431
settings.setValue(reposName + "/enabled", bool(dlg.checkBoxEnabled.checkState()))
431432
# refresh lists and populate widgets
432433
plugins.removeRepository(reposName)
@@ -442,6 +443,7 @@ def editRepository(self, reposName):
442443
dlg = QgsPluginInstallerRepositoryDialog(iface.mainWindow())
443444
dlg.editName.setText(reposName)
444445
dlg.editURL.setText(repositories.all()[reposName]["url"])
446+
dlg.editAuthCfg.setText(repositories.all()[reposName]["authcfg"])
445447
dlg.editParams.setText(repositories.urlParams())
446448
dlg.checkBoxEnabled.setCheckState(checkState[repositories.all()[reposName]["enabled"]])
447449
if repositories.all()[reposName]["valid"]:
@@ -465,7 +467,10 @@ def editRepository(self, reposName):
465467
if newName in repositories.all() and newName != reposName:
466468
newName = newName + "(2)"
467469
settings.setValue(newName + "/url", dlg.editURL.text().strip())
470+
settings.setValue(newName + "/authcfg", dlg.editAuthCfg.text().strip())
468471
settings.setValue(newName + "/enabled", bool(dlg.checkBoxEnabled.checkState()))
472+
if dlg.editAuthCfg.text().strip() != repositories.all()[reposName]["authcfg"]:
473+
repositories.all()[reposName]["authcfg"] = dlg.editAuthCfg.text().strip()
469474
if dlg.editURL.text().strip() == repositories.all()[reposName]["url"] and dlg.checkBoxEnabled.checkState() == checkState[repositories.all()[reposName]["enabled"]]:
470475
repositories.rename(reposName, newName)
471476
self.exportRepositoriesToManager()

python/pyplugin_installer/installer_data.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
import codecs
3232
import ConfigParser
3333
import qgis.utils
34-
from qgis.core import QGis, QgsNetworkAccessManager
34+
from qgis.core import QGis, QgsNetworkAccessManager, QgsAuthManager
35+
from qgis.gui import QgsMessageBar
3536
from qgis.utils import iface, plugin_paths
3637
from version_compare import compareVersions, normalizeVersion, isCompatible
3738

@@ -320,6 +321,7 @@ def load(self):
320321
for key in settings.childGroups():
321322
self.mRepositories[key] = {}
322323
self.mRepositories[key]["url"] = settings.value(key + "/url", "", type=unicode)
324+
self.mRepositories[key]["authcfg"] = settings.value(key + "/authcfg", "", type=unicode)
323325
self.mRepositories[key]["enabled"] = settings.value(key + "/enabled", True, type=bool)
324326
self.mRepositories[key]["valid"] = settings.value(key + "/valid", True, type=bool)
325327
self.mRepositories[key]["Relay"] = Relay(key)
@@ -337,6 +339,17 @@ def requestFetching(self, key):
337339
#url.addQueryItem('qgis', '.'.join([str(int(s)) for s in [v[0], v[1:3]]]) ) # don't include the bugfix version!
338340

339341
self.mRepositories[key]["QRequest"] = QNetworkRequest(url)
342+
authcfg = self.mRepositories[key]["authcfg"]
343+
if authcfg and isinstance(authcfg, basestring):
344+
if not QgsAuthManager.instance().updateNetworkRequest(
345+
self.mRepositories[key]["QRequest"], authcfg.strip()):
346+
msg = QCoreApplication.translate(
347+
"QgsPluginInstaller",
348+
"Update of network request with authentication "
349+
"credentials FAILED for configuration '{0}'").format(authcfg)
350+
iface.pluginManagerInterface().pushMessage(msg, QgsMessageBar.WARNING)
351+
self.mRepositories[key]["QRequest"] = None
352+
return
340353
self.mRepositories[key]["QRequest"].setAttribute(QNetworkRequest.User, key)
341354
self.mRepositories[key]["xmlData"] = QgsNetworkAccessManager.instance().get(self.mRepositories[key]["QRequest"])
342355
self.mRepositories[key]["xmlData"].setProperty('reposName', key)

python/pyplugin_installer/qgsplugininstallerrepositorybase.ui

+143-96
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<rect>
88
<x>0</x>
99
<y>0</y>
10-
<width>522</width>
11-
<height>185</height>
10+
<width>496</width>
11+
<height>289</height>
1212
</rect>
1313
</property>
1414
<property name="sizePolicy">
@@ -27,7 +27,89 @@
2727
<string/>
2828
</property>
2929
<layout class="QGridLayout">
30-
<item row="5" column="1" colspan="2">
30+
<item row="5" column="2">
31+
<spacer>
32+
<property name="orientation">
33+
<enum>Qt::Horizontal</enum>
34+
</property>
35+
<property name="sizeType">
36+
<enum>QSizePolicy::Fixed</enum>
37+
</property>
38+
<property name="sizeHint" stdset="0">
39+
<size>
40+
<width>351</width>
41+
<height>23</height>
42+
</size>
43+
</property>
44+
</spacer>
45+
</item>
46+
<item row="1" column="0">
47+
<widget class="QLabel" name="label_2">
48+
<property name="text">
49+
<string>URL</string>
50+
</property>
51+
<property name="buddy">
52+
<cstring>editURL</cstring>
53+
</property>
54+
</widget>
55+
</item>
56+
<item row="5" column="0">
57+
<widget class="QLabel" name="label_4">
58+
<property name="text">
59+
<string>Enabled</string>
60+
</property>
61+
<property name="buddy">
62+
<cstring>checkBoxEnabled</cstring>
63+
</property>
64+
</widget>
65+
</item>
66+
<item row="0" column="1" colspan="2">
67+
<widget class="QLineEdit" name="editName">
68+
<property name="toolTip">
69+
<string>Enter a name for the repository</string>
70+
</property>
71+
<property name="whatsThis">
72+
<string>Enter a name for the repository</string>
73+
</property>
74+
</widget>
75+
</item>
76+
<item row="3" column="1" colspan="2">
77+
<widget class="QLineEdit" name="editParams">
78+
<property name="enabled">
79+
<bool>false</bool>
80+
</property>
81+
<property name="text">
82+
<string>?qgis=</string>
83+
</property>
84+
</widget>
85+
</item>
86+
<item row="9" column="0" colspan="3">
87+
<widget class="QDialogButtonBox" name="buttonBox">
88+
<property name="orientation">
89+
<enum>Qt::Horizontal</enum>
90+
</property>
91+
<property name="standardButtons">
92+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
93+
</property>
94+
</widget>
95+
</item>
96+
<item row="0" column="0">
97+
<widget class="QLabel" name="label">
98+
<property name="sizePolicy">
99+
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
100+
<horstretch>0</horstretch>
101+
<verstretch>0</verstretch>
102+
</sizepolicy>
103+
</property>
104+
<property name="text">
105+
<string>Name</string>
106+
</property>
107+
<property name="buddy">
108+
<cstring>editName</cstring>
109+
</property>
110+
</widget>
111+
</item>
112+
<item row="7" column="1" colspan="2">
31113
<widget class="QLabel" name="labelInfo">
32114
<property name="enabled">
33115
<bool>true</bool>
@@ -89,59 +171,17 @@
89171
</property>
90172
</widget>
91173
</item>
92-
<item row="7" column="0" colspan="3">
93-
<widget class="QDialogButtonBox" name="buttonBox">
94-
<property name="orientation">
95-
<enum>Qt::Horizontal</enum>
96-
</property>
97-
<property name="standardButtons">
98-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
99-
</property>
100-
</widget>
101-
</item>
102-
<item row="0" column="0">
103-
<widget class="QLabel" name="label">
104-
<property name="sizePolicy">
105-
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
106-
<horstretch>0</horstretch>
107-
<verstretch>0</verstretch>
108-
</sizepolicy>
109-
</property>
174+
<item row="3" column="0">
175+
<widget class="QLabel" name="label_3">
110176
<property name="text">
111-
<string>Name</string>
177+
<string>Parameters</string>
112178
</property>
113179
<property name="buddy">
114-
<cstring>editName</cstring>
115-
</property>
116-
</widget>
117-
</item>
118-
<item row="4" column="1" colspan="2">
119-
<spacer name="verticalSpacer">
120-
<property name="orientation">
121-
<enum>Qt::Vertical</enum>
122-
</property>
123-
<property name="sizeHint" stdset="0">
124-
<size>
125-
<width>20</width>
126-
<height>40</height>
127-
</size>
128-
</property>
129-
</spacer>
130-
</item>
131-
<item row="1" column="1" colspan="2">
132-
<widget class="QLineEdit" name="editURL">
133-
<property name="toolTip">
134-
<string>Enter the repository URL, beginning with &quot;http://&quot;</string>
135-
</property>
136-
<property name="whatsThis">
137-
<string>Enter the repository URL, beginning with &quot;http://&quot;</string>
138-
</property>
139-
<property name="text">
140-
<string/>
180+
<cstring>editParams</cstring>
141181
</property>
142182
</widget>
143183
</item>
144-
<item row="3" column="1">
184+
<item row="5" column="1">
145185
<widget class="QCheckBox" name="checkBoxEnabled">
146186
<property name="enabled">
147187
<bool>true</bool>
@@ -166,72 +206,79 @@
166206
</property>
167207
</widget>
168208
</item>
169-
<item row="2" column="0">
170-
<widget class="QLabel" name="label_3">
171-
<property name="text">
172-
<string>Parameters</string>
173-
</property>
174-
<property name="buddy">
175-
<cstring>editParams</cstring>
176-
</property>
177-
</widget>
178-
</item>
179-
<item row="2" column="1" colspan="2">
180-
<widget class="QLineEdit" name="editParams">
181-
<property name="enabled">
182-
<bool>false</bool>
183-
</property>
184-
<property name="text">
185-
<string>?qgis=</string>
186-
</property>
187-
</widget>
188-
</item>
189-
<item row="0" column="1" colspan="2">
190-
<widget class="QLineEdit" name="editName">
209+
<item row="1" column="1" colspan="2">
210+
<widget class="QLineEdit" name="editURL">
191211
<property name="toolTip">
192-
<string>Enter a name for the repository</string>
212+
<string>Enter the repository URL, beginning with &quot;http://&quot;</string>
193213
</property>
194214
<property name="whatsThis">
195-
<string>Enter a name for the repository</string>
215+
<string>Enter the repository URL, beginning with &quot;http://&quot;</string>
196216
</property>
197-
</widget>
198-
</item>
199-
<item row="1" column="0">
200-
<widget class="QLabel" name="label_2">
201217
<property name="text">
202-
<string>URL</string>
203-
</property>
204-
<property name="buddy">
205-
<cstring>editURL</cstring>
218+
<string/>
206219
</property>
207220
</widget>
208221
</item>
209-
<item row="3" column="2">
210-
<spacer>
222+
<item row="6" column="1" colspan="2">
223+
<spacer name="verticalSpacer">
211224
<property name="orientation">
212-
<enum>Qt::Horizontal</enum>
213-
</property>
214-
<property name="sizeType">
215-
<enum>QSizePolicy::Fixed</enum>
225+
<enum>Qt::Vertical</enum>
216226
</property>
217227
<property name="sizeHint" stdset="0">
218228
<size>
219-
<width>351</width>
220-
<height>23</height>
229+
<width>20</width>
230+
<height>40</height>
221231
</size>
222232
</property>
223233
</spacer>
224234
</item>
225-
<item row="3" column="0">
226-
<widget class="QLabel" name="label_4">
235+
<item row="4" column="0">
236+
<widget class="QLabel" name="label_5">
227237
<property name="text">
228-
<string>Enabled</string>
229-
</property>
230-
<property name="buddy">
231-
<cstring>checkBoxEnabled</cstring>
238+
<string>Authentication</string>
232239
</property>
233240
</widget>
234241
</item>
242+
<item row="4" column="1" colspan="2">
243+
<layout class="QHBoxLayout" name="layoutAuthCfg">
244+
<property name="spacing">
245+
<number>6</number>
246+
</property>
247+
<item>
248+
<widget class="QLineEdit" name="editAuthCfg">
249+
<property name="readOnly">
250+
<bool>true</bool>
251+
</property>
252+
</widget>
253+
</item>
254+
<item>
255+
<widget class="QToolButton" name="btnClearAuthCfg">
256+
<property name="maximumSize">
257+
<size>
258+
<width>16777215</width>
259+
<height>22</height>
260+
</size>
261+
</property>
262+
<property name="text">
263+
<string>Clear</string>
264+
</property>
265+
</widget>
266+
</item>
267+
<item>
268+
<widget class="QToolButton" name="btnEditAuthCfg">
269+
<property name="maximumSize">
270+
<size>
271+
<width>16777215</width>
272+
<height>22</height>
273+
</size>
274+
</property>
275+
<property name="text">
276+
<string>Edit</string>
277+
</property>
278+
</widget>
279+
</item>
280+
</layout>
281+
</item>
235282
</layout>
236283
</widget>
237284
<tabstops>

python/pyplugin_installer/qgsplugininstallerrepositorydialog.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
***************************************************************************/
2525
"""
2626

27-
from PyQt4.QtGui import QDialog, QDialogButtonBox
27+
from qgis.gui import QgsAuthConfigSelect
28+
from PyQt4.QtGui import QDialog, QDialogButtonBox, QVBoxLayout
29+
from PyQt4.QtCore import Qt
2830

2931
from ui_qgsplugininstallerrepositorybase import Ui_QgsPluginInstallerRepositoryDetailsDialogBase
3032

@@ -38,9 +40,28 @@ def __init__(self, parent=None):
3840
self.editURL.setText("http://")
3941
self.editName.textChanged.connect(self.textChanged)
4042
self.editURL.textChanged.connect(self.textChanged)
43+
self.btnClearAuthCfg.clicked.connect(self.editAuthCfg.clear)
44+
self.btnEditAuthCfg.clicked.connect(self.editAuthCfgId)
4145
self.textChanged(None)
4246

4347
# ----------------------------------------- #
4448
def textChanged(self, string):
4549
enable = (len(self.editName.text()) > 0 and len(self.editURL.text()) > 0)
4650
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
51+
52+
def editAuthCfgId(self):
53+
dlg = QDialog(self)
54+
dlg.setWindowModality(Qt.WindowModal)
55+
layout = QVBoxLayout()
56+
selector = QgsAuthConfigSelect(self)
57+
if self.editAuthCfg.text():
58+
selector.setConfigId(self.editAuthCfg.text())
59+
layout.addWidget(selector)
60+
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Close)
61+
buttonBox.accepted.connect(dlg.accept)
62+
buttonBox.rejected.connect(dlg.reject)
63+
layout.addWidget(buttonBox)
64+
dlg.setLayout(layout)
65+
if dlg.exec_():
66+
self.editAuthCfg.setText(selector.configId())
67+
del dlg

0 commit comments

Comments
 (0)