Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
e2fbfa74
Commit
e2fbfa74
authored
Jun 22, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modtools: Better error reporting
parent
a31d2451
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
45 deletions
+100
-45
spec/modtools.js
spec/modtools.js
+83
-34
src/modals/moderator-tools.js
src/modals/moderator-tools.js
+17
-11
No files found.
spec/modtools.js
View file @
e2fbfa74
...
@@ -7,6 +7,18 @@ const sizzle = converse.env.sizzle;
...
@@ -7,6 +7,18 @@ const sizzle = converse.env.sizzle;
const
Strophe
=
converse
.
env
.
Strophe
;
const
Strophe
=
converse
.
env
.
Strophe
;
const
u
=
converse
.
env
.
utils
;
const
u
=
converse
.
env
.
utils
;
async
function
openModtools
(
view
)
{
const
textarea
=
view
.
el
.
querySelector
(
'
.chat-textarea
'
);
textarea
.
value
=
'
/modtools
'
;
const
enter
=
{
'
target
'
:
textarea
,
'
preventDefault
'
:
function
preventDefault
()
{},
'
keyCode
'
:
13
};
view
.
onKeyDown
(
enter
);
await
u
.
waitUntil
(()
=>
view
.
showModeratorToolsModal
.
calls
.
count
());
const
modal
=
view
.
modtools_modal
;
await
u
.
waitUntil
(()
=>
u
.
isVisible
(
modal
.
el
),
1000
);
return
modal
;
}
describe
(
"
The groupchat moderator tool
"
,
function
()
{
describe
(
"
The groupchat moderator tool
"
,
function
()
{
it
(
"
allows you to set affiliations and roles
"
,
it
(
"
allows you to set affiliations and roles
"
,
...
@@ -28,14 +40,7 @@ describe("The groupchat moderator tool", function () {
...
@@ -28,14 +40,7 @@ describe("The groupchat moderator tool", function () {
const
view
=
_converse
.
chatboxviews
.
get
(
muc_jid
);
const
view
=
_converse
.
chatboxviews
.
get
(
muc_jid
);
await
u
.
waitUntil
(()
=>
(
view
.
model
.
occupants
.
length
===
5
),
1000
);
await
u
.
waitUntil
(()
=>
(
view
.
model
.
occupants
.
length
===
5
),
1000
);
const
textarea
=
view
.
el
.
querySelector
(
'
.chat-textarea
'
);
const
modal
=
await
openModtools
(
view
);
textarea
.
value
=
'
/modtools
'
;
const
enter
=
{
'
target
'
:
textarea
,
'
preventDefault
'
:
function
preventDefault
()
{},
'
keyCode
'
:
13
};
view
.
onKeyDown
(
enter
);
await
u
.
waitUntil
(()
=>
view
.
showModeratorToolsModal
.
calls
.
count
());
const
modal
=
view
.
modtools_modal
;
await
u
.
waitUntil
(()
=>
u
.
isVisible
(
modal
.
el
),
1000
);
let
tab
=
modal
.
el
.
querySelector
(
'
#affiliations-tab
'
);
let
tab
=
modal
.
el
.
querySelector
(
'
#affiliations-tab
'
);
// Clear so that we don't match older stanzas
// Clear so that we don't match older stanzas
_converse
.
connection
.
IQ_stanzas
=
[];
_converse
.
connection
.
IQ_stanzas
=
[];
...
@@ -156,16 +161,9 @@ describe("The groupchat moderator tool", function () {
...
@@ -156,16 +161,9 @@ describe("The groupchat moderator tool", function () {
const
view
=
_converse
.
chatboxviews
.
get
(
muc_jid
);
const
view
=
_converse
.
chatboxviews
.
get
(
muc_jid
);
await
u
.
waitUntil
(()
=>
(
view
.
model
.
occupants
.
length
===
6
),
1000
);
await
u
.
waitUntil
(()
=>
(
view
.
model
.
occupants
.
length
===
6
),
1000
);
const
textarea
=
view
.
el
.
querySelector
(
'
.chat-textarea
'
);
textarea
.
value
=
'
/modtools
'
;
const
enter
=
{
'
target
'
:
textarea
,
'
preventDefault
'
:
function
preventDefault
()
{},
'
keyCode
'
:
13
};
view
.
onKeyDown
(
enter
);
await
u
.
waitUntil
(()
=>
view
.
showModeratorToolsModal
.
calls
.
count
());
const
modal
=
view
.
modtools_modal
;
await
u
.
waitUntil
(()
=>
u
.
isVisible
(
modal
.
el
),
1000
);
// Clear so that we don't match older stanzas
// Clear so that we don't match older stanzas
_converse
.
connection
.
IQ_stanzas
=
[];
_converse
.
connection
.
IQ_stanzas
=
[];
const
modal
=
await
openModtools
(
view
);
const
select
=
modal
.
el
.
querySelector
(
'
.select-affiliation
'
);
const
select
=
modal
.
el
.
querySelector
(
'
.select-affiliation
'
);
expect
(
select
.
value
).
toBe
(
'
owner
'
);
expect
(
select
.
value
).
toBe
(
'
owner
'
);
select
.
value
=
'
member
'
;
select
.
value
=
'
member
'
;
...
@@ -328,15 +326,7 @@ describe("The groupchat moderator tool", function () {
...
@@ -328,15 +326,7 @@ describe("The groupchat moderator tool", function () {
await
mock
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
[],
members
);
await
mock
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
[],
members
);
const
view
=
_converse
.
chatboxviews
.
get
(
muc_jid
);
const
view
=
_converse
.
chatboxviews
.
get
(
muc_jid
);
await
u
.
waitUntil
(()
=>
(
view
.
model
.
occupants
.
length
===
5
));
await
u
.
waitUntil
(()
=>
(
view
.
model
.
occupants
.
length
===
5
));
const
modal
=
await
openModtools
(
view
);
const
textarea
=
view
.
el
.
querySelector
(
'
.chat-textarea
'
);
textarea
.
value
=
'
/modtools
'
;
const
enter
=
{
'
target
'
:
textarea
,
'
preventDefault
'
:
function
preventDefault
()
{},
'
keyCode
'
:
13
};
view
.
onKeyDown
(
enter
);
await
u
.
waitUntil
(()
=>
view
.
showModeratorToolsModal
.
calls
.
count
());
const
modal
=
view
.
modtools_modal
;
await
u
.
waitUntil
(()
=>
u
.
isVisible
(
modal
.
el
),
1000
);
const
tab
=
modal
.
el
.
querySelector
(
'
#affiliations-tab
'
);
const
tab
=
modal
.
el
.
querySelector
(
'
#affiliations-tab
'
);
// Clear so that we don't match older stanzas
// Clear so that we don't match older stanzas
_converse
.
connection
.
IQ_stanzas
=
[];
_converse
.
connection
.
IQ_stanzas
=
[];
...
@@ -371,6 +361,73 @@ describe("The groupchat moderator tool", function () {
...
@@ -371,6 +361,73 @@ describe("The groupchat moderator tool", function () {
done
();
done
();
}));
}));
it
(
"
shows an error message if a particular affiliation may not be set
"
,
mock
.
initConverse
(
[
'
rosterGroupsFetched
'
],
{},
async
function
(
done
,
_converse
)
{
spyOn
(
_converse
.
ChatRoomView
.
prototype
,
'
showModeratorToolsModal
'
).
and
.
callThrough
();
const
muc_jid
=
'
lounge@montague.lit
'
;
const
members
=
[
{
'
jid
'
:
'
gower@shakespeare.lit
'
,
'
nick
'
:
'
gower
'
,
'
affiliation
'
:
'
member
'
},
{
'
jid
'
:
'
romeo@montague.lit
'
,
'
nick
'
:
'
romeo
'
,
'
affiliation
'
:
'
owner
'
},
];
await
mock
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
[],
members
);
const
view
=
_converse
.
chatboxviews
.
get
(
muc_jid
);
await
u
.
waitUntil
(()
=>
(
view
.
model
.
occupants
.
length
===
2
));
const
modal
=
await
openModtools
(
view
);
// Clear so that we don't match older stanzas
_converse
.
connection
.
IQ_stanzas
=
[];
const
tab
=
modal
.
el
.
querySelector
(
'
#affiliations-tab
'
);
tab
.
click
();
const
select
=
modal
.
el
.
querySelector
(
'
.select-affiliation
'
);
select
.
value
=
'
member
'
;
const
button
=
modal
.
el
.
querySelector
(
'
.btn-primary[name="users_with_affiliation"]
'
);
button
.
click
();
await
u
.
waitUntil
(()
=>
!
modal
.
loading_users_with_affiliation
);
const
user_els
=
modal
.
el
.
querySelectorAll
(
'
.list-group--users > li
'
);
expect
(
user_els
.
length
).
toBe
(
1
);
const
toggle
=
user_els
[
0
].
querySelector
(
'
.list-group-item:nth-child(3n) .toggle-form
'
);
const
form
=
user_els
[
0
].
querySelector
(
'
.list-group-item:nth-child(3n) .affiliation-form
'
);
expect
(
u
.
hasClass
(
'
hidden
'
,
form
)).
toBeTruthy
();
toggle
.
click
();
expect
(
u
.
hasClass
(
'
hidden
'
,
form
)).
toBeFalsy
();
const
change_affiliation_dropdown
=
form
.
querySelector
(
'
.select-affiliation
'
);
expect
(
change_affiliation_dropdown
.
value
).
toBe
(
'
member
'
);
change_affiliation_dropdown
.
value
=
'
admin
'
;
const
input
=
form
.
querySelector
(
'
input[name="reason"]
'
);
input
.
value
=
"
You're an admin now
"
;
const
submit
=
form
.
querySelector
(
'
.btn-primary
'
);
submit
.
click
();
const
sent_IQ
=
_converse
.
connection
.
IQ_stanzas
.
pop
();
expect
(
Strophe
.
serialize
(
sent_IQ
)).
toBe
(
`<iq id="
${
sent_IQ
.
getAttribute
(
'
id
'
)}
" to="lounge@montague.lit" type="set" xmlns="jabber:client">`
+
`<query xmlns="http://jabber.org/protocol/muc#admin">`
+
`<item affiliation="admin" jid="gower@shakespeare.lit">`
+
`<reason>You're an admin now</reason>`
+
`</item>`
+
`</query>`
+
`</iq>`
);
const
error
=
u
.
toStanza
(
`<iq from="
${
muc_jid
}
"
id="
${
sent_IQ
.
getAttribute
(
'
id
'
)}
"
type="error"
to="
${
_converse
.
jid
}
">
<error type="cancel">
<not-allowed xmlns="
${
Strophe
.
NS
.
STANZAS
}
"/>
</error>
</iq>`
);
_converse
.
connection
.
_dataRecv
(
mock
.
createRequest
(
error
));
done
();
}));
it
(
"
doesn't allow admins to make more admins
"
,
it
(
"
doesn't allow admins to make more admins
"
,
mock
.
initConverse
(
mock
.
initConverse
(
[
'
rosterGroupsFetched
'
],
{},
[
'
rosterGroupsFetched
'
],
{},
...
@@ -386,15 +443,7 @@ describe("The groupchat moderator tool", function () {
...
@@ -386,15 +443,7 @@ describe("The groupchat moderator tool", function () {
await
mock
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
[],
members
);
await
mock
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
[],
members
);
const
view
=
_converse
.
chatboxviews
.
get
(
muc_jid
);
const
view
=
_converse
.
chatboxviews
.
get
(
muc_jid
);
await
u
.
waitUntil
(()
=>
(
view
.
model
.
occupants
.
length
===
3
));
await
u
.
waitUntil
(()
=>
(
view
.
model
.
occupants
.
length
===
3
));
const
modal
=
await
openModtools
(
view
);
const
textarea
=
view
.
el
.
querySelector
(
'
.chat-textarea
'
);
textarea
.
value
=
'
/modtools
'
;
const
enter
=
{
'
target
'
:
textarea
,
'
preventDefault
'
:
function
preventDefault
()
{},
'
keyCode
'
:
13
};
view
.
onKeyDown
(
enter
);
await
u
.
waitUntil
(()
=>
view
.
showModeratorToolsModal
.
calls
.
count
());
const
modal
=
view
.
modtools_modal
;
await
u
.
waitUntil
(()
=>
u
.
isVisible
(
modal
.
el
),
1000
);
const
tab
=
modal
.
el
.
querySelector
(
'
#affiliations-tab
'
);
const
tab
=
modal
.
el
.
querySelector
(
'
#affiliations-tab
'
);
// Clear so that we don't match older stanzas
// Clear so that we don't match older stanzas
_converse
.
connection
.
IQ_stanzas
=
[];
_converse
.
connection
.
IQ_stanzas
=
[];
...
...
src/modals/moderator-tools.js
View file @
e2fbfa74
...
@@ -147,7 +147,7 @@ export default BootstrapModal.extend({
...
@@ -147,7 +147,7 @@ export default BootstrapModal.extend({
this
.
model
.
set
({
'
affiliation
'
:
affiliation
});
this
.
model
.
set
({
'
affiliation
'
:
affiliation
});
},
},
assignAffiliation
(
ev
)
{
as
ync
as
signAffiliation
(
ev
)
{
ev
.
stopPropagation
();
ev
.
stopPropagation
();
ev
.
preventDefault
();
ev
.
preventDefault
();
const
data
=
new
FormData
(
ev
.
target
);
const
data
=
new
FormData
(
ev
.
target
);
...
@@ -157,17 +157,23 @@ export default BootstrapModal.extend({
...
@@ -157,17 +157,23 @@ export default BootstrapModal.extend({
'
reason
'
:
data
.
get
(
'
reason
'
)
'
reason
'
:
data
.
get
(
'
reason
'
)
}
}
const
current_affiliation
=
this
.
model
.
get
(
'
affiliation
'
);
const
current_affiliation
=
this
.
model
.
get
(
'
affiliation
'
);
t
his
.
chatroomview
.
model
.
setAffiliation
(
affiliation
,
[
attrs
])
t
ry
{
.
then
(
async
()
=>
{
await
this
.
chatroomview
.
model
.
setAffiliation
(
affiliation
,
[
attrs
]);
this
.
alert
(
__
(
'
Affiliation changed
'
),
'
primary
'
);
}
catch
(
e
)
{
await
this
.
chatroomview
.
model
.
occupants
.
fetchMembers
()
if
(
e
===
null
)
{
this
.
model
.
set
({
'
affiliation
'
:
null
},
{
'
silent
'
:
true
}
);
this
.
alert
(
__
(
'
Timeout error while trying to set the affiliation
'
),
'
danger
'
);
this
.
model
.
set
({
'
affiliation
'
:
current_affiliation
});
}
else
if
(
sizzle
(
`not-allowed[xmlns="
${
Strophe
.
NS
.
STANZAS
}
"]`
,
e
).
length
)
{
})
this
.
alert
(
__
(
'
Sorry, you
\'
re not allowed to make that change
'
),
'
danger
'
);
.
catch
(
err
=>
{
}
else
{
this
.
alert
(
__
(
'
Sorry, something went wrong while trying to set the affiliation
'
),
'
danger
'
);
this
.
alert
(
__
(
'
Sorry, something went wrong while trying to set the affiliation
'
),
'
danger
'
);
log
.
error
(
err
);
}
});
log
.
error
(
e
);
return
;
}
this
.
alert
(
__
(
'
Affiliation changed
'
),
'
primary
'
);
await
this
.
chatroomview
.
model
.
occupants
.
fetchMembers
()
this
.
model
.
set
({
'
affiliation
'
:
null
},
{
'
silent
'
:
true
});
this
.
model
.
set
({
'
affiliation
'
:
current_affiliation
});
},
},
assignRole
(
ev
)
{
assignRole
(
ev
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment