Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maySendRedactionForEvent for userId #435

Merged
merged 5 commits into from
May 23, 2017
Merged

maySendRedactionForEvent for userId #435

merged 5 commits into from
May 23, 2017

Conversation

t3chguy
Copy link
Member

@t3chguy t3chguy commented May 16, 2017

allows to more nicely fix element-hq/element-web/issues/273

Signed-off-by: Michael Telatynski [email protected]

edit:
d182fd6 means can't redact things with that string/enum set as they're not really complete

done using a private helper so kick/ban etc perms can be done
easily at a later stage

Signed-off-by: Michael Telatynski <[email protected]>
t3chguy added a commit to element-hq/element-web that referenced this pull request May 16, 2017
Signed-off-by: Michael Telatynski <[email protected]>
`--max-warnings 115` :')

Signed-off-by: Michael Telatynski <[email protected]>
* @param {string} userId The user ID of the user to test permission for
* @return {boolean} true if the given user ID has sufficient power level
*/
RoomState.prototype._hasSufficientPowerLevelFor = function(type, userId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unclear how this differs from maySendEvent ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maySendEvent checks inside power_levels.events.X yet this checks power_levels.X
Can't check whether we can redact using maySendEvent

requiredLevel = powerLevels[type];
}

return member.powerLevel >= requiredLevel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

member may be null/undef, and this will throw. Also: need to check for leave membership

(Alternatively, if you're relying on maySendRedactionForEvent having checked this already, just pass in member.powerlevel rather than the userid.)

powerLevels = powerLevelsEvent.getContent();
}

let requiredLevel = powerLevels.state_default || 50;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

powerLevels may be undef, this will throw

default is 50, not state_default

};

/**
* Returns true if the given user ID has sufficient power level for type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type confused me here: maybe action ?

Signed-off-by: Michael Telatynski <[email protected]>
}

let requiredLevel = 50;
if (powerLevels[action] !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can still be undef?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it can't :)
PTAL @richvdh

Signed-off-by: Michael Telatynski <[email protected]>
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@richvdh richvdh merged commit 0eb5b0f into matrix-org:develop May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redact buttons should only be shown if you have privileges to use them
2 participants