Skip to content

Commit dc9a299

Browse files
committed
feat(governance): makes our apply labels dialog usefull
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
1 parent b8437e9 commit dc9a299

19 files changed

Lines changed: 556 additions & 97 deletions

src/gui/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ set(client_SRCS
225225
governance/typedwithlabelidgovernancenetworkjob.cpp
226226
governance/governancelabelinfo.h
227227
governance/governancelabelinfo.cpp
228+
governance/governancelabelslistmodel.h
229+
governance/governancelabelslistmodel.cpp
230+
governance/governancetypes.h
228231
tray/svgimageprovider.h
229232
tray/svgimageprovider.cpp
230233
tray/syncstatussummary.h

src/gui/GovernanceLabelsDialog.qml

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ ApplicationWindow {
9292
entityId: governanceLabelsDialog.fileId
9393
}
9494

95+
GovernanceLabelsListModel {
96+
id: labelsModel
97+
98+
entityId: governanceLabelsDialog.fileId
99+
labelType: GovernanceNetworkJob.Sensitivity
100+
101+
onRefreshData: function(labelType, entityId) {
102+
getAvailableGovernanceLabelsForSensitivity.start()
103+
}
104+
}
105+
95106
ColumnLayout {
96107
anchors.fill: parent
97108
anchors.leftMargin: 10
@@ -101,42 +112,33 @@ ApplicationWindow {
101112
spacing: 15
102113
z: 2
103114

104-
Button {
105-
text: 'Apply governance label'
106-
onClicked: applyGovernanceLabel.start()
107-
}
115+
EnforcedPlainTextLabel {
116+
text: 'Sensitivity label:'
108117

109-
Button {
110-
text: 'Delete governance label'
111-
onClicked: deleteGovernanceLabel.start()
118+
font.pixelSize: Style.pixelSize + 2
112119
}
113120

114-
Button {
115-
text: 'Get available governance labels for sensitivity'
116-
onClicked: getAvailableGovernanceLabelsForSensitivity.start()
117-
}
118-
119-
Button {
120-
text: 'Get available governance labels for retention'
121-
onClicked: getAvailableGovernanceLabelsForRetention.start()
122-
}
121+
ComboBox {
122+
id: selectedNewSensitivityLabel
123123

124-
Button {
125-
text: 'Get available governance labels for legal hold'
126-
onClicked: getAvailableGovernanceLabelsForHold.start()
127-
}
124+
font.pixelSize: Style.pixelSize + 2
125+
Accessible.role: Accessible.ComboBox
126+
Accessible.name: qsTr("Select sensitivity label")
128127

129-
Button {
130-
text: 'Get governance labels'
131-
onClicked: getGovernanceLabels.start()
128+
model: labelsModel
132129
}
133130

134131
DialogButtonBox {
135132
Layout.fillWidth: true
136133

137134
Button {
138-
text: qsTr("Close")
139-
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
135+
text: qsTr("Apply")
136+
DialogButtonBox.buttonRole: DialogButtonBox.ApplyRole
137+
}
138+
139+
Button {
140+
text: qsTr("Cancel")
141+
DialogButtonBox.buttonRole: DialogButtonBox.RejectRole
140142
}
141143

142144
onAccepted: function() {

src/gui/governance/applygovernancelabel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ ApplyGovernanceLabel::ApplyGovernanceLabel(QObject *parent)
1717

1818
void ApplyGovernanceLabel::start()
1919
{
20+
if (!checkParameters()) {
21+
Q_EMIT finishedWitherror(500, {});
22+
return;
23+
}
24+
2025
setOcsGovernanceJob(QPointer<OcsGovernanceJob>{new OcsGovernanceJob{account()}});
2126

2227
connect(ocsGovernanceJob().data(), &OcsJob::jobFinished,

src/gui/governance/deletegovernancelabel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ DeleteGovernanceLabel::DeleteGovernanceLabel(QObject *parent)
1717

1818
void DeleteGovernanceLabel::start()
1919
{
20+
if (!checkParameters()) {
21+
Q_EMIT finishedWitherror(500, {});
22+
return;
23+
}
24+
2025
setOcsGovernanceJob(QPointer<OcsGovernanceJob>{new OcsGovernanceJob{account()}});
2126

2227
connect(ocsGovernanceJob().data(), &OcsJob::jobFinished,

src/gui/governance/getavailablegovernancelabels.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ GetAvailableGovernanceLabels::GetAvailableGovernanceLabels(QObject *parent)
1919

2020
void GetAvailableGovernanceLabels::start()
2121
{
22+
if (!checkParameters()) {
23+
Q_EMIT finishedWitherror(500, {});
24+
return;
25+
}
26+
2227
setOcsGovernanceJob(QPointer<OcsGovernanceJob>{new OcsGovernanceJob{account()}});
2328

2429
connect(ocsGovernanceJob().data(), &OcsJob::jobFinished,

src/gui/governance/getgovernancelabels.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ GetGovernanceLabels::GetGovernanceLabels(QObject *parent)
1717

1818
void GetGovernanceLabels::start()
1919
{
20+
if (!checkParameters()) {
21+
Q_EMIT finishedWitherror(500, {});
22+
return;
23+
}
24+
2025
setOcsGovernanceJob(QPointer<OcsGovernanceJob>{new OcsGovernanceJob{account()}});
2126

2227
connect(ocsGovernanceJob().data(), &OcsJob::jobFinished,

src/gui/governance/governancelabelinfo.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@
88
namespace OCC
99
{
1010

11-
GOvernanceLabelInfo::GOvernanceLabelInfo()
12-
{
13-
}
14-
1511
} // namespace OCC

src/gui/governance/governancelabelinfo.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
namespace OCC
1313
{
1414

15-
struct GOvernanceLabelInfo
15+
struct GovernanceLabelInfo
1616
{
1717
public:
18-
GOvernanceLabelInfo();
19-
2018
QString _id;
2119

2220
QString _name;
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: GPL-2.0-or-later
4+
*/
5+
6+
#include "governancelabelslistmodel.h"
7+
8+
#include <QLoggingCategory>
9+
#include <QJsonDocument>
10+
#include <QJsonObject>
11+
#include <QJsonArray>
12+
13+
using namespace Qt::StringLiterals;
14+
15+
namespace OCC
16+
{
17+
18+
Q_LOGGING_CATEGORY(lcGovernanceLabelsListModel, "nextcloud.gui.governance.labelslistmodel", QtInfoMsg)
19+
20+
GovernanceLabelsListModel::GovernanceLabelsListModel(QObject *parent)
21+
: QAbstractListModel(parent)
22+
{
23+
}
24+
25+
int GovernanceLabelsListModel::rowCount(const QModelIndex &parent) const
26+
{
27+
auto result = 0;
28+
if (parent.isValid()) {
29+
return result;
30+
}
31+
32+
result = _data.count();
33+
return result;
34+
}
35+
36+
QVariant GovernanceLabelsListModel::data(const QModelIndex &index, int role) const
37+
{
38+
auto result = QVariant{};
39+
40+
if (!index.isValid()) {
41+
return result;
42+
}
43+
44+
if (index.column() != 0) {
45+
return result;
46+
}
47+
48+
if (index.row() < 0 || index.row() >= _data.count()) {
49+
return result;
50+
}
51+
52+
if (role >= Qt::UserRole + 1) {
53+
auto convertedRole = static_cast<LabelsListModelRoles>(role);
54+
55+
switch (convertedRole)
56+
{
57+
case LabelsListModelRoles::IdRole:
58+
result = _data[index.row()]._id;
59+
break;
60+
case LabelsListModelRoles::NameRole:
61+
result = _data[index.row()]._name;
62+
break;
63+
case LabelsListModelRoles::PriorityRole:
64+
result = _data[index.row()]._priority;
65+
break;
66+
case LabelsListModelRoles::DescriptionRole:
67+
result = _data[index.row()]._description;
68+
break;
69+
case LabelsListModelRoles::ColorRole:
70+
result = _data[index.row()]._color;
71+
break;
72+
case LabelsListModelRoles::ScopesRole:
73+
result = _data[index.row()]._scopes;
74+
break;
75+
}
76+
}
77+
78+
return result;
79+
}
80+
81+
QHash<int, QByteArray> GovernanceLabelsListModel::roleNames() const
82+
{
83+
auto result = QHash<int, QByteArray>{
84+
{static_cast<int>(LabelsListModelRoles::IdRole), "id"_ba},
85+
{static_cast<int>(LabelsListModelRoles::NameRole), "name"_ba},
86+
{static_cast<int>(LabelsListModelRoles::PriorityRole), "priority"_ba},
87+
{static_cast<int>(LabelsListModelRoles::DescriptionRole), "description"_ba},
88+
{static_cast<int>(LabelsListModelRoles::ColorRole), "color"_ba},
89+
{static_cast<int>(LabelsListModelRoles::ScopesRole), "scopes"_ba},
90+
};
91+
92+
return result;
93+
}
94+
95+
Governance::LabelType GovernanceLabelsListModel::labelType() const
96+
{
97+
return _labelType;
98+
}
99+
100+
void GovernanceLabelsListModel::setLabelType(Governance::LabelType newLabelType)
101+
{
102+
if (_labelType == newLabelType) {
103+
return;
104+
}
105+
106+
_labelType = newLabelType;
107+
Q_EMIT labelTypeChanged();
108+
109+
emitRefreshData();
110+
}
111+
112+
QString GovernanceLabelsListModel::entityId() const
113+
{
114+
return _entityId;
115+
}
116+
117+
void GovernanceLabelsListModel::setEntityId(const QString &newEntityId)
118+
{
119+
if (_entityId == newEntityId) {
120+
return;
121+
}
122+
123+
_entityId = newEntityId;
124+
Q_EMIT entityIdChanged();
125+
126+
emitRefreshData();
127+
}
128+
129+
void GovernanceLabelsListModel::setAvailableLabelsJsonData(const QJsonDocument &reply)
130+
{
131+
const auto replyObject = reply.object();
132+
133+
if (!replyObject.contains(u"ocs"_s)) {
134+
qCWarning(lcGovernanceLabelsListModel()) << "wrong format for reply" << reply.toJson(QJsonDocument::JsonFormat::Compact);
135+
return;
136+
}
137+
138+
const auto ocsObject = replyObject.value(u"ocs"_s).toObject();
139+
140+
if (!ocsObject.contains(u"data"_s)) {
141+
qCWarning(lcGovernanceLabelsListModel()) << "wrong format for reply" << ocsObject;
142+
return;
143+
}
144+
145+
const auto dataArray = ocsObject.value(u"data"_s).toArray();
146+
147+
const auto convertToStringList = [] (const QJsonArray &scopesList) -> QStringList
148+
{
149+
auto result = QStringList{};
150+
151+
for (const auto &oneScope : scopesList) {
152+
result << oneScope.toString();
153+
}
154+
155+
return result;
156+
};
157+
158+
beginResetModel();
159+
_data.clear();
160+
for (const auto oneLabel : dataArray) {
161+
const auto oneLabelObject = oneLabel.toObject();
162+
_data.emplaceBack(oneLabelObject.value(u"id"_s).toString(),
163+
oneLabelObject.value(u"name"_s).toString(),
164+
oneLabelObject.value(u"priority"_s).toInt(),
165+
oneLabelObject.value(u"description"_s).toString(),
166+
oneLabelObject.value(u"color"_s).toString(),
167+
convertToStringList(oneLabelObject.value(u"scopes"_s).toArray())
168+
);
169+
}
170+
endResetModel();
171+
}
172+
173+
void GovernanceLabelsListModel::setExistingLabelsJsonData(const QJsonDocument &data)
174+
{
175+
qCInfo(lcGovernanceLabelsListModel()) << data.toJson(QJsonDocument::JsonFormat::Compact);
176+
}
177+
178+
void OCC::GovernanceLabelsListModel::etagChanged()
179+
{
180+
Q_EMIT refreshData(_labelType, _entityId);
181+
}
182+
183+
void GovernanceLabelsListModel::emitRefreshData()
184+
{
185+
if (_entityId.isEmpty() || _labelType == Governance::LabelType::Invalid) {
186+
return;
187+
}
188+
189+
Q_EMIT refreshData(_labelType, _entityId);
190+
}
191+
192+
} // namespace OCC

0 commit comments

Comments
 (0)