-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix allowing multiple puppets on the same team for the same user (#705)
* Add new schema to prevent multiple puppets on the same team * Test * Fix tests * Notify users of account violations * Notice * Fix NEDB test * Check error message in test * Cleanup schema * Fix type bug * spell sql out * fix sql
- Loading branch information
Showing
6 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Disallowed the accidental behaviour of puppeting two or more Slack accounts from the same team to the same Matrix user. This would cause all puppeting for the | ||
user to stop working. The bridge will now **automatically delete** any puppeted connections which violate this rule. You will be notified via the bridge when | ||
this happens, so you can relink your accounts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { IDatabase } from "pg-promise"; | ||
|
||
import { SchemaRunUserMessage } from "../PgDatastore"; | ||
|
||
export const runSchema = async(db: IDatabase<unknown>): Promise<{userMessages: SchemaRunUserMessage[]}> => { | ||
// Disallow multiple puppets for the same team for the same user. | ||
const cases =(await db.manyOrNone( | ||
`SELECT matrixuser, name FROM ( | ||
SELECT slackteam, matrixuser FROM puppets | ||
GROUP BY slackteam, matrixuser HAVING COUNT(*) > 1 | ||
) entry | ||
LEFT JOIN teams ON entry.slackteam = teams.id;`)).map((puppet => ({ | ||
matrixId: puppet.matrixuser, | ||
// It's possible the team name might not exist (rarely), so just hide it. | ||
teamName: puppet.name ? ` (${puppet.name})` : '', | ||
}))); | ||
// Delete any cases where this has happened | ||
await db.none(` | ||
DELETE FROM puppets puppetsOuter USING ( | ||
SELECT matrixuser, slackteam FROM puppets GROUP BY slackteam, matrixuser HAVING COUNT(*) > 1 | ||
) puppetsInner WHERE puppetsOuter.matrixuser = puppetsInner.matrixuser AND puppetsOuter.slackteam = puppetsInner.slackteam; | ||
ALTER TABLE puppets ADD CONSTRAINT puppets_slackteam_matrixuser_unique UNIQUE(slackteam, matrixuser);`); | ||
return { | ||
userMessages: cases.map(u => ({ | ||
matrixId: u.matrixId, | ||
message: `Hello. Your Matrix account was puppeted to two or more Slack accounts from the same team${u.teamName}, which` + | ||
` is not valid. As a precaution, the bridge has unlinked all Slack accounts where two or more were present from the same team.` + | ||
` You can use the \`whoami\` command to find out if any accounts are still linked. To relink your accounts, simply run \`login\`. | ||
` | ||
})), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters