Socket
Socket
Sign inDemoInstall

@esri/hub-discussions

Package Overview
Dependencies
Maintainers
43
Versions
284
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esri/hub-discussions - npm Package Compare versions

Comparing version 25.4.1 to 25.5.0

dist/esm/utils/posts/can-delete-post.js

200

dist/esm/utils/channel-permission.js

@@ -5,3 +5,3 @@ import { AclCategory, AclSubCategory, Role, } from "../types";

export class ChannelPermission {
constructor(channelAcl) {
constructor(channelAcl, creator) {
this.ALLOWED_GROUP_MEMBER_TYPES = ["owner", "admin", "member"];

@@ -17,2 +17,3 @@ this.ADMIN_GROUP_MEMBER_TYPES = ["owner", "admin"];

this.permissionsByCategory = {};
this.channelCreator = creator;
channelAcl.forEach((permission) => {

@@ -26,3 +27,3 @@ var _a;

canPostToChannel(user) {
if (this.aclAllowsAnyUserToPost()) {
if (this.canAnyUserWrite()) {
return true;

@@ -33,10 +34,7 @@ }

}
return (this.aclAllowsAnyAuthenticatedUserToPost() ||
this.aclAllowsThisUserToPost(user) ||
this.aclAllowsThisUserToPostByGroups(user) ||
this.aclAllowsThisUserToPostByOrg(user));
return (this.canAnyAuthenticatedUserWrite() ||
this.isUserAWriteUser(user) ||
this.isUserPartOfWriteGroup(user) ||
this.isUserPartOfWriteOrg(user));
}
canModifyPostStatus(user, channelCreator) {
return this.canModifyChannel(user, channelCreator);
}
canCreateChannel(user) {

@@ -52,54 +50,70 @@ if (this.isUserUnAuthenticated(user) || this.isChannelAclEmpty) {

}
canModifyChannel(user, channelCreator) {
canModerateChannel(user) {
if (this.isUserUnAuthenticated(user)) {
return false;
}
if (user.username === channelCreator) {
return (user.username === this.channelCreator ||
this.isUserAModeratorUser(user) ||
this.isUserPartOfModeratorGroup(user) ||
this.isUserPartOfModeratorOrg(user));
}
/**
* canCreateChannelHelpers
*/
userCanAddAnonymousToAcl(user) {
if (!this.permissionsByCategory[AclCategory.ANONYMOUS_USER]) {
return true;
}
return (this.aclAllowsThisUserToModifyChannel(user) ||
this.aclAllowsThisUserToModifyChannelByGroups(user) ||
this.aclAllowsThisUserToModifyChannelByOrg(user));
return isOrgAdmin(user);
}
isAuthorizedToPost(role) {
return this.ALLOWED_ROLES_FOR_POSTING.includes(role);
userCanAddUnauthenticatedToAcl(user) {
if (!this.permissionsByCategory[AclCategory.AUTHENTICATED_USER]) {
return true;
}
return isOrgAdmin(user);
}
isAuthorizedToModerate(role) {
return this.ALLOWED_ROLES_FOR_MODERATION.includes(role);
userCanAddAllGroupsToAcl(user) {
const groupPermissions = this.permissionsByCategory[AclCategory.GROUP];
const userGroupsById = this.mapUserGroupsById(user.groups);
if (!groupPermissions) {
return true;
}
return groupPermissions.every((permission) => {
const userGroup = userGroupsById[permission.key];
return (userGroup &&
this.isMemberTypeAuthorized(userGroup) &&
this.isGroupDiscussable(userGroup));
});
}
isUserUnAuthenticated(user) {
return user.username === null || user.username === undefined;
userCanAddAllOrgsToAcl(user) {
const orgPermissions = this.permissionsByCategory[AclCategory.ORG];
if (!orgPermissions) {
return true;
}
return (isOrgAdmin(user) &&
this.isEveryPermissionForUserOrg(user.orgId, orgPermissions));
}
mapUserGroupsById(groups) {
return groups.reduce((accum, userGroup) => {
accum[userGroup.id] = userGroup;
return accum;
}, {});
isEveryPermissionForUserOrg(userOrgId, orgPermissions) {
return orgPermissions.every((permission) => {
const { key: orgId } = permission;
return userOrgId === orgId;
});
}
isMemberTypeAuthorized(userGroup) {
const { userMembership: { memberType }, } = userGroup;
return this.ALLOWED_GROUP_MEMBER_TYPES.includes(memberType);
// for now user permissions are disabled on channel create
// since users are not notified and cannot opt out
userCanAddUsersToAcl(user) {
const userPermissions = this.permissionsByCategory[AclCategory.USER];
return !userPermissions;
}
isMemberTypeAdmin(userGroup) {
const { userMembership: { memberType }, } = userGroup;
return this.ADMIN_GROUP_MEMBER_TYPES.includes(memberType);
}
isGroupDiscussable(userGroup) {
const { typeKeywords = [] } = userGroup;
return !typeKeywords.includes(CANNOT_DISCUSS);
}
/**
* canPostToChannel helpers
*/
aclAllowsAnyUserToPost() {
canAnyUserWrite() {
var _a;
const role = (_a = this.permissionsByCategory[AclCategory.ANONYMOUS_USER]) === null || _a === void 0 ? void 0 : _a[0].role;
return this.isAuthorizedToPost(role);
return this.isAuthorizedToWritePost(role);
}
aclAllowsAnyAuthenticatedUserToPost() {
canAnyAuthenticatedUserWrite() {
var _a;
const role = (_a = this.permissionsByCategory[AclCategory.AUTHENTICATED_USER]) === null || _a === void 0 ? void 0 : _a[0].role;
return this.isAuthorizedToPost(role);
return this.isAuthorizedToWritePost(role);
}
aclAllowsThisUserToPost(user) {
isUserAWriteUser(user) {
var _a;

@@ -110,6 +124,6 @@ const userPermissions = (_a = this.permissionsByCategory[AclCategory.USER]) !== null && _a !== void 0 ? _a : [];

const { role, key } = permission;
return key === username && this.isAuthorizedToPost(role);
return key === username && this.isAuthorizedToWritePost(role);
});
}
aclAllowsThisUserToPostByGroups(user) {
isUserPartOfWriteGroup(user) {
var _a;

@@ -129,9 +143,10 @@ const groupPermissions = (_a = this.permissionsByCategory[AclCategory.GROUP]) !== null && _a !== void 0 ? _a : [];

const { subCategory, role } = permission;
return (subCategory === AclSubCategory.MEMBER && this.isAuthorizedToPost(role));
return (subCategory === AclSubCategory.MEMBER &&
this.isAuthorizedToWritePost(role));
}
canAdminsPost(permission) {
const { subCategory, role } = permission;
return (subCategory === AclSubCategory.ADMIN && this.isAuthorizedToPost(role));
return (subCategory === AclSubCategory.ADMIN && this.isAuthorizedToWritePost(role));
}
aclAllowsThisUserToPostByOrg(user) {
isUserPartOfWriteOrg(user) {
var _a;

@@ -149,8 +164,33 @@ const orgPermissions = (_a = this.permissionsByCategory[AclCategory.ORG]) !== null && _a !== void 0 ? _a : [];

const { subCategory, role } = permission;
return (subCategory === AclSubCategory.MEMBER && this.isAuthorizedToPost(role));
return (subCategory === AclSubCategory.MEMBER &&
this.isAuthorizedToWritePost(role));
}
/**
* canModifyChannel helpers
*/
aclAllowsThisUserToModifyChannel(user) {
isAuthorizedToWritePost(role) {
return this.ALLOWED_ROLES_FOR_POSTING.includes(role);
}
isUserUnAuthenticated(user) {
return user.username === null || user.username === undefined;
}
mapUserGroupsById(groups) {
return groups.reduce((accum, userGroup) => {
accum[userGroup.id] = userGroup;
return accum;
}, {});
}
isMemberTypeAuthorized(userGroup) {
const { userMembership: { memberType }, } = userGroup;
return this.ALLOWED_GROUP_MEMBER_TYPES.includes(memberType);
}
isMemberTypeAdmin(userGroup) {
const { userMembership: { memberType }, } = userGroup;
return this.ADMIN_GROUP_MEMBER_TYPES.includes(memberType);
}
isGroupDiscussable(userGroup) {
const { typeKeywords = [] } = userGroup;
return !typeKeywords.includes(CANNOT_DISCUSS);
}
isAuthorizedToModerate(role) {
return this.ALLOWED_ROLES_FOR_MODERATION.includes(role);
}
isUserAModeratorUser(user) {
var _a;

@@ -164,3 +204,3 @@ const userPermissions = (_a = this.permissionsByCategory[AclCategory.USER]) !== null && _a !== void 0 ? _a : [];

}
aclAllowsThisUserToModifyChannelByGroups(user) {
isUserPartOfModeratorGroup(user) {
var _a;

@@ -186,3 +226,3 @@ const groupPermissions = (_a = this.permissionsByCategory[AclCategory.GROUP]) !== null && _a !== void 0 ? _a : [];

}
aclAllowsThisUserToModifyChannelByOrg(user) {
isUserPartOfModeratorOrg(user) {
var _a;

@@ -202,51 +242,3 @@ const orgPermissions = (_a = this.permissionsByCategory[AclCategory.ORG]) !== null && _a !== void 0 ? _a : [];

}
/**
* canCreateChannelHelpers
*/
userCanAddAnonymousToAcl(user) {
if (!this.permissionsByCategory[AclCategory.ANONYMOUS_USER]) {
return true;
}
return isOrgAdmin(user);
}
userCanAddUnauthenticatedToAcl(user) {
if (!this.permissionsByCategory[AclCategory.AUTHENTICATED_USER]) {
return true;
}
return isOrgAdmin(user);
}
userCanAddAllGroupsToAcl(user) {
const groupPermissions = this.permissionsByCategory[AclCategory.GROUP];
const userGroupsById = this.mapUserGroupsById(user.groups);
if (!groupPermissions) {
return true;
}
return groupPermissions.every((permission) => {
const userGroup = userGroupsById[permission.key];
return (userGroup &&
this.isMemberTypeAuthorized(userGroup) &&
this.isGroupDiscussable(userGroup));
});
}
userCanAddAllOrgsToAcl(user) {
const orgPermissions = this.permissionsByCategory[AclCategory.ORG];
if (!orgPermissions) {
return true;
}
return (isOrgAdmin(user) &&
this.isEveryPermissionForUserOrg(user.orgId, orgPermissions));
}
isEveryPermissionForUserOrg(userOrgId, orgPermissions) {
return orgPermissions.every((permission) => {
const { key: orgId } = permission;
return userOrgId === orgId;
});
}
// for now user permissions are disabled on channel create
// since users are not notified and cannot opt out
userCanAddUsersToAcl(user) {
const userPermissions = this.permissionsByCategory[AclCategory.USER];
return !userPermissions;
}
}
//# sourceMappingURL=channel-permission.js.map

@@ -12,5 +12,5 @@ import { SharingAccess } from "../../types";

export function canCreateChannel(channel, user = {}) {
const { channelAcl, access, groups, orgs } = channel;
const { channelAcl, access, groups, orgs, creator } = channel;
if (channelAcl) {
const channelPermission = new ChannelPermission(channelAcl);
const channelPermission = new ChannelPermission(channelAcl, creator);
return channelPermission.canCreateChannel(user);

@@ -17,0 +17,0 @@ }

@@ -12,6 +12,6 @@ import { SharingAccess } from "../../types";

export function canModifyChannel(channel, user = {}) {
const { channelAcl } = channel;
const { channelAcl, creator } = channel;
if (channelAcl) {
const channelPermission = new ChannelPermission(channelAcl);
return channelPermission.canModifyChannel(user, channel.creator);
const channelPermission = new ChannelPermission(channelAcl, creator);
return channelPermission.canModerateChannel(user);
}

@@ -18,0 +18,0 @@ return isAuthorizedToModifyChannelByLegacyPermissions(user, channel);

@@ -19,5 +19,5 @@ import { Role, SharingAccess } from "../../types";

export function canPostToChannel(channel, user = {}) {
const { channelAcl, access, groups, orgs, allowAnonymous } = channel;
const { channelAcl, access, groups, orgs, allowAnonymous, creator } = channel;
if (channelAcl) {
const channelPermission = new ChannelPermission(channelAcl);
const channelPermission = new ChannelPermission(channelAcl, creator);
return channelPermission.canPostToChannel(user);

@@ -24,0 +24,0 @@ }

@@ -12,6 +12,6 @@ import { SharingAccess } from "../../types";

export function canModifyPostStatus(channel, user = {}) {
const { channelAcl } = channel;
const { channelAcl, creator } = channel;
if (channelAcl) {
const channelPermission = new ChannelPermission(channelAcl);
return channelPermission.canModifyPostStatus(user, channel.creator);
const channelPermission = new ChannelPermission(channelAcl, creator);
return channelPermission.canModerateChannel(user);
}

@@ -18,0 +18,0 @@ return isAuthorizedToModifyStatusByLegacyPermissions(user, channel);

import { SharingAccess } from "../../types";
import { CANNOT_DISCUSS } from "../constants";
import { ChannelPermission } from "../channel-permission";
/**

@@ -11,3 +12,7 @@ * Utility to determine if User has privileges to modify a post

export function canModifyPost(post, user = {}, channel) {
const { access, groups, orgs, allowAnonymous } = channel;
const { access, groups, orgs, allowAnonymous, channelAcl, creator } = channel;
if (channelAcl) {
const channelPermission = new ChannelPermission(channelAcl, creator);
return (isPostCreator(post, user) && channelPermission.canPostToChannel(user));
}
return (isPostCreator(post, user) &&

@@ -14,0 +19,0 @@ isAuthorizedToModifyByLegacyPermissions(user, {

import { parseDatasetId } from "@esri/hub-common";
import { canModifyChannel } from "../channels";
import { MENTION_ATTRIBUTE } from "../constants";
export { canModifyPost } from "./can-modify-post";
export { canDeletePost } from "./can-delete-post";
export { canModifyPostStatus } from "./can-modify-post-status";

@@ -43,15 +43,2 @@ export { isDiscussable } from "@esri/hub-common";

}
/**
* Determines if the given user has sufficient privileges to delete the given post
* @param post An IPost object
* @param channel An IChannel object
* @param user An IUser object
* @returns true if the user can delete the post
*/
export function canDeletePost(post, channel, user = {}) {
return isPostCreator(post, user) || canModifyChannel(channel, user);
}
function isPostCreator(post, user) {
return !!user.username && post.creator === user.username;
}
const MENTION_ATTRIBUTE_AND_VALUE_PATTERN = new RegExp(`${MENTION_ATTRIBUTE}=('|")[\\w@\\.-]+('|")`, "g");

@@ -58,0 +45,0 @@ const MENTION_ATTRIBUTE_PATTERN = new RegExp(`${MENTION_ATTRIBUTE}=`, "g");

@@ -8,3 +8,3 @@ "use strict";

class ChannelPermission {
constructor(channelAcl) {
constructor(channelAcl, creator) {
this.ALLOWED_GROUP_MEMBER_TYPES = ["owner", "admin", "member"];

@@ -20,2 +20,3 @@ this.ADMIN_GROUP_MEMBER_TYPES = ["owner", "admin"];

this.permissionsByCategory = {};
this.channelCreator = creator;
channelAcl.forEach((permission) => {

@@ -29,3 +30,3 @@ var _a;

canPostToChannel(user) {
if (this.aclAllowsAnyUserToPost()) {
if (this.canAnyUserWrite()) {
return true;

@@ -36,10 +37,7 @@ }

}
return (this.aclAllowsAnyAuthenticatedUserToPost() ||
this.aclAllowsThisUserToPost(user) ||
this.aclAllowsThisUserToPostByGroups(user) ||
this.aclAllowsThisUserToPostByOrg(user));
return (this.canAnyAuthenticatedUserWrite() ||
this.isUserAWriteUser(user) ||
this.isUserPartOfWriteGroup(user) ||
this.isUserPartOfWriteOrg(user));
}
canModifyPostStatus(user, channelCreator) {
return this.canModifyChannel(user, channelCreator);
}
canCreateChannel(user) {

@@ -55,54 +53,70 @@ if (this.isUserUnAuthenticated(user) || this.isChannelAclEmpty) {

}
canModifyChannel(user, channelCreator) {
canModerateChannel(user) {
if (this.isUserUnAuthenticated(user)) {
return false;
}
if (user.username === channelCreator) {
return (user.username === this.channelCreator ||
this.isUserAModeratorUser(user) ||
this.isUserPartOfModeratorGroup(user) ||
this.isUserPartOfModeratorOrg(user));
}
/**
* canCreateChannelHelpers
*/
userCanAddAnonymousToAcl(user) {
if (!this.permissionsByCategory[types_1.AclCategory.ANONYMOUS_USER]) {
return true;
}
return (this.aclAllowsThisUserToModifyChannel(user) ||
this.aclAllowsThisUserToModifyChannelByGroups(user) ||
this.aclAllowsThisUserToModifyChannelByOrg(user));
return platform_1.isOrgAdmin(user);
}
isAuthorizedToPost(role) {
return this.ALLOWED_ROLES_FOR_POSTING.includes(role);
userCanAddUnauthenticatedToAcl(user) {
if (!this.permissionsByCategory[types_1.AclCategory.AUTHENTICATED_USER]) {
return true;
}
return platform_1.isOrgAdmin(user);
}
isAuthorizedToModerate(role) {
return this.ALLOWED_ROLES_FOR_MODERATION.includes(role);
userCanAddAllGroupsToAcl(user) {
const groupPermissions = this.permissionsByCategory[types_1.AclCategory.GROUP];
const userGroupsById = this.mapUserGroupsById(user.groups);
if (!groupPermissions) {
return true;
}
return groupPermissions.every((permission) => {
const userGroup = userGroupsById[permission.key];
return (userGroup &&
this.isMemberTypeAuthorized(userGroup) &&
this.isGroupDiscussable(userGroup));
});
}
isUserUnAuthenticated(user) {
return user.username === null || user.username === undefined;
userCanAddAllOrgsToAcl(user) {
const orgPermissions = this.permissionsByCategory[types_1.AclCategory.ORG];
if (!orgPermissions) {
return true;
}
return (platform_1.isOrgAdmin(user) &&
this.isEveryPermissionForUserOrg(user.orgId, orgPermissions));
}
mapUserGroupsById(groups) {
return groups.reduce((accum, userGroup) => {
accum[userGroup.id] = userGroup;
return accum;
}, {});
isEveryPermissionForUserOrg(userOrgId, orgPermissions) {
return orgPermissions.every((permission) => {
const { key: orgId } = permission;
return userOrgId === orgId;
});
}
isMemberTypeAuthorized(userGroup) {
const { userMembership: { memberType }, } = userGroup;
return this.ALLOWED_GROUP_MEMBER_TYPES.includes(memberType);
// for now user permissions are disabled on channel create
// since users are not notified and cannot opt out
userCanAddUsersToAcl(user) {
const userPermissions = this.permissionsByCategory[types_1.AclCategory.USER];
return !userPermissions;
}
isMemberTypeAdmin(userGroup) {
const { userMembership: { memberType }, } = userGroup;
return this.ADMIN_GROUP_MEMBER_TYPES.includes(memberType);
}
isGroupDiscussable(userGroup) {
const { typeKeywords = [] } = userGroup;
return !typeKeywords.includes(constants_1.CANNOT_DISCUSS);
}
/**
* canPostToChannel helpers
*/
aclAllowsAnyUserToPost() {
canAnyUserWrite() {
var _a;
const role = (_a = this.permissionsByCategory[types_1.AclCategory.ANONYMOUS_USER]) === null || _a === void 0 ? void 0 : _a[0].role;
return this.isAuthorizedToPost(role);
return this.isAuthorizedToWritePost(role);
}
aclAllowsAnyAuthenticatedUserToPost() {
canAnyAuthenticatedUserWrite() {
var _a;
const role = (_a = this.permissionsByCategory[types_1.AclCategory.AUTHENTICATED_USER]) === null || _a === void 0 ? void 0 : _a[0].role;
return this.isAuthorizedToPost(role);
return this.isAuthorizedToWritePost(role);
}
aclAllowsThisUserToPost(user) {
isUserAWriteUser(user) {
var _a;

@@ -113,6 +127,6 @@ const userPermissions = (_a = this.permissionsByCategory[types_1.AclCategory.USER]) !== null && _a !== void 0 ? _a : [];

const { role, key } = permission;
return key === username && this.isAuthorizedToPost(role);
return key === username && this.isAuthorizedToWritePost(role);
});
}
aclAllowsThisUserToPostByGroups(user) {
isUserPartOfWriteGroup(user) {
var _a;

@@ -132,9 +146,10 @@ const groupPermissions = (_a = this.permissionsByCategory[types_1.AclCategory.GROUP]) !== null && _a !== void 0 ? _a : [];

const { subCategory, role } = permission;
return (subCategory === types_1.AclSubCategory.MEMBER && this.isAuthorizedToPost(role));
return (subCategory === types_1.AclSubCategory.MEMBER &&
this.isAuthorizedToWritePost(role));
}
canAdminsPost(permission) {
const { subCategory, role } = permission;
return (subCategory === types_1.AclSubCategory.ADMIN && this.isAuthorizedToPost(role));
return (subCategory === types_1.AclSubCategory.ADMIN && this.isAuthorizedToWritePost(role));
}
aclAllowsThisUserToPostByOrg(user) {
isUserPartOfWriteOrg(user) {
var _a;

@@ -152,8 +167,33 @@ const orgPermissions = (_a = this.permissionsByCategory[types_1.AclCategory.ORG]) !== null && _a !== void 0 ? _a : [];

const { subCategory, role } = permission;
return (subCategory === types_1.AclSubCategory.MEMBER && this.isAuthorizedToPost(role));
return (subCategory === types_1.AclSubCategory.MEMBER &&
this.isAuthorizedToWritePost(role));
}
/**
* canModifyChannel helpers
*/
aclAllowsThisUserToModifyChannel(user) {
isAuthorizedToWritePost(role) {
return this.ALLOWED_ROLES_FOR_POSTING.includes(role);
}
isUserUnAuthenticated(user) {
return user.username === null || user.username === undefined;
}
mapUserGroupsById(groups) {
return groups.reduce((accum, userGroup) => {
accum[userGroup.id] = userGroup;
return accum;
}, {});
}
isMemberTypeAuthorized(userGroup) {
const { userMembership: { memberType }, } = userGroup;
return this.ALLOWED_GROUP_MEMBER_TYPES.includes(memberType);
}
isMemberTypeAdmin(userGroup) {
const { userMembership: { memberType }, } = userGroup;
return this.ADMIN_GROUP_MEMBER_TYPES.includes(memberType);
}
isGroupDiscussable(userGroup) {
const { typeKeywords = [] } = userGroup;
return !typeKeywords.includes(constants_1.CANNOT_DISCUSS);
}
isAuthorizedToModerate(role) {
return this.ALLOWED_ROLES_FOR_MODERATION.includes(role);
}
isUserAModeratorUser(user) {
var _a;

@@ -167,3 +207,3 @@ const userPermissions = (_a = this.permissionsByCategory[types_1.AclCategory.USER]) !== null && _a !== void 0 ? _a : [];

}
aclAllowsThisUserToModifyChannelByGroups(user) {
isUserPartOfModeratorGroup(user) {
var _a;

@@ -189,3 +229,3 @@ const groupPermissions = (_a = this.permissionsByCategory[types_1.AclCategory.GROUP]) !== null && _a !== void 0 ? _a : [];

}
aclAllowsThisUserToModifyChannelByOrg(user) {
isUserPartOfModeratorOrg(user) {
var _a;

@@ -205,52 +245,4 @@ const orgPermissions = (_a = this.permissionsByCategory[types_1.AclCategory.ORG]) !== null && _a !== void 0 ? _a : [];

}
/**
* canCreateChannelHelpers
*/
userCanAddAnonymousToAcl(user) {
if (!this.permissionsByCategory[types_1.AclCategory.ANONYMOUS_USER]) {
return true;
}
return platform_1.isOrgAdmin(user);
}
userCanAddUnauthenticatedToAcl(user) {
if (!this.permissionsByCategory[types_1.AclCategory.AUTHENTICATED_USER]) {
return true;
}
return platform_1.isOrgAdmin(user);
}
userCanAddAllGroupsToAcl(user) {
const groupPermissions = this.permissionsByCategory[types_1.AclCategory.GROUP];
const userGroupsById = this.mapUserGroupsById(user.groups);
if (!groupPermissions) {
return true;
}
return groupPermissions.every((permission) => {
const userGroup = userGroupsById[permission.key];
return (userGroup &&
this.isMemberTypeAuthorized(userGroup) &&
this.isGroupDiscussable(userGroup));
});
}
userCanAddAllOrgsToAcl(user) {
const orgPermissions = this.permissionsByCategory[types_1.AclCategory.ORG];
if (!orgPermissions) {
return true;
}
return (platform_1.isOrgAdmin(user) &&
this.isEveryPermissionForUserOrg(user.orgId, orgPermissions));
}
isEveryPermissionForUserOrg(userOrgId, orgPermissions) {
return orgPermissions.every((permission) => {
const { key: orgId } = permission;
return userOrgId === orgId;
});
}
// for now user permissions are disabled on channel create
// since users are not notified and cannot opt out
userCanAddUsersToAcl(user) {
const userPermissions = this.permissionsByCategory[types_1.AclCategory.USER];
return !userPermissions;
}
}
exports.ChannelPermission = ChannelPermission;
//# sourceMappingURL=channel-permission.js.map

@@ -15,5 +15,5 @@ "use strict";

function canCreateChannel(channel, user = {}) {
const { channelAcl, access, groups, orgs } = channel;
const { channelAcl, access, groups, orgs, creator } = channel;
if (channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl);
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl, creator);
return channelPermission.canCreateChannel(user);

@@ -20,0 +20,0 @@ }

@@ -15,6 +15,6 @@ "use strict";

function canModifyChannel(channel, user = {}) {
const { channelAcl } = channel;
const { channelAcl, creator } = channel;
if (channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl);
return channelPermission.canModifyChannel(user, channel.creator);
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl, creator);
return channelPermission.canModerateChannel(user);
}

@@ -21,0 +21,0 @@ return isAuthorizedToModifyChannelByLegacyPermissions(user, channel);

@@ -22,5 +22,5 @@ "use strict";

function canPostToChannel(channel, user = {}) {
const { channelAcl, access, groups, orgs, allowAnonymous } = channel;
const { channelAcl, access, groups, orgs, allowAnonymous, creator } = channel;
if (channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl);
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl, creator);
return channelPermission.canPostToChannel(user);

@@ -27,0 +27,0 @@ }

@@ -15,6 +15,6 @@ "use strict";

function canModifyPostStatus(channel, user = {}) {
const { channelAcl } = channel;
const { channelAcl, creator } = channel;
if (channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl);
return channelPermission.canModifyPostStatus(user, channel.creator);
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl, creator);
return channelPermission.canModerateChannel(user);
}

@@ -21,0 +21,0 @@ return isAuthorizedToModifyStatusByLegacyPermissions(user, channel);

@@ -6,2 +6,3 @@ "use strict";

const constants_1 = require("../constants");
const channel_permission_1 = require("../channel-permission");
/**

@@ -15,3 +16,7 @@ * Utility to determine if User has privileges to modify a post

function canModifyPost(post, user = {}, channel) {
const { access, groups, orgs, allowAnonymous } = channel;
const { access, groups, orgs, allowAnonymous, channelAcl, creator } = channel;
if (channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl, creator);
return (isPostCreator(post, user) && channelPermission.canPostToChannel(user));
}
return (isPostCreator(post, user) &&

@@ -18,0 +23,0 @@ isAuthorizedToModifyByLegacyPermissions(user, {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseMentionedUsers = exports.canDeletePost = exports.parseDiscussionURI = void 0;
exports.parseMentionedUsers = exports.parseDiscussionURI = void 0;
const hub_common_1 = require("@esri/hub-common");
const channels_1 = require("../channels");
const constants_1 = require("../constants");
var can_modify_post_1 = require("./can-modify-post");
Object.defineProperty(exports, "canModifyPost", { enumerable: true, get: function () { return can_modify_post_1.canModifyPost; } });
var can_delete_post_1 = require("./can-delete-post");
Object.defineProperty(exports, "canDeletePost", { enumerable: true, get: function () { return can_delete_post_1.canDeletePost; } });
var can_modify_post_status_1 = require("./can-modify-post-status");

@@ -50,16 +51,2 @@ Object.defineProperty(exports, "canModifyPostStatus", { enumerable: true, get: function () { return can_modify_post_status_1.canModifyPostStatus; } });

exports.parseDiscussionURI = parseDiscussionURI;
/**
* Determines if the given user has sufficient privileges to delete the given post
* @param post An IPost object
* @param channel An IChannel object
* @param user An IUser object
* @returns true if the user can delete the post
*/
function canDeletePost(post, channel, user = {}) {
return isPostCreator(post, user) || channels_1.canModifyChannel(channel, user);
}
exports.canDeletePost = canDeletePost;
function isPostCreator(post, user) {
return !!user.username && post.creator === user.username;
}
const MENTION_ATTRIBUTE_AND_VALUE_PATTERN = new RegExp(`${constants_1.MENTION_ATTRIBUTE}=('|")[\\w@\\.-]+('|")`, "g");

@@ -66,0 +53,0 @@ const MENTION_ATTRIBUTE_PATTERN = new RegExp(`${constants_1.MENTION_ATTRIBUTE}=`, "g");

@@ -9,35 +9,8 @@ import { IChannelAclPermission, IDiscussionsUser } from "../types";

private permissionsByCategory;
constructor(channelAcl: IChannelAclPermission[]);
private channelCreator;
constructor(channelAcl: IChannelAclPermission[], creator: string);
canPostToChannel(user: IDiscussionsUser): boolean;
canModifyPostStatus(user: IDiscussionsUser, channelCreator: string): boolean;
canCreateChannel(user: IDiscussionsUser): boolean;
canModifyChannel(user: IDiscussionsUser, channelCreator: string): boolean;
private isAuthorizedToPost;
private isAuthorizedToModerate;
private isUserUnAuthenticated;
private mapUserGroupsById;
private isMemberTypeAuthorized;
private isMemberTypeAdmin;
private isGroupDiscussable;
canModerateChannel(user: IDiscussionsUser): boolean;
/**
* canPostToChannel helpers
*/
private aclAllowsAnyUserToPost;
private aclAllowsAnyAuthenticatedUserToPost;
private aclAllowsThisUserToPost;
private aclAllowsThisUserToPostByGroups;
private canAnyGroupMemberPost;
private canAdminsPost;
private aclAllowsThisUserToPostByOrg;
private canAnyOrgMemberPost;
/**
* canModifyChannel helpers
*/
private aclAllowsThisUserToModifyChannel;
private aclAllowsThisUserToModifyChannelByGroups;
private canAnyGroupMemberModerate;
private canAdminsModerate;
private aclAllowsThisUserToModifyChannelByOrg;
private canAnyOrgMemberModerate;
/**
* canCreateChannelHelpers

@@ -51,2 +24,23 @@ */

private userCanAddUsersToAcl;
private canAnyUserWrite;
private canAnyAuthenticatedUserWrite;
private isUserAWriteUser;
private isUserPartOfWriteGroup;
private canAnyGroupMemberPost;
private canAdminsPost;
private isUserPartOfWriteOrg;
private canAnyOrgMemberPost;
private isAuthorizedToWritePost;
private isUserUnAuthenticated;
private mapUserGroupsById;
private isMemberTypeAuthorized;
private isMemberTypeAdmin;
private isGroupDiscussable;
private isAuthorizedToModerate;
private isUserAModeratorUser;
private isUserPartOfModeratorGroup;
private canAnyGroupMemberModerate;
private canAdminsModerate;
private isUserPartOfModeratorOrg;
private canAnyOrgMemberModerate;
}

@@ -1,4 +0,4 @@

import { IChannel, IDiscussionParams, IDiscussionsUser, IPost } from "../../types";
import { IUser } from "@esri/arcgis-rest-auth";
import { IDiscussionParams } from "../../types";
export { canModifyPost } from "./can-modify-post";
export { canDeletePost } from "./can-delete-post";
export { canModifyPostStatus } from "./can-modify-post-status";

@@ -15,10 +15,2 @@ export { isDiscussable } from "@esri/hub-common";

/**
* Determines if the given user has sufficient privileges to delete the given post
* @param post An IPost object
* @param channel An IChannel object
* @param user An IUser object
* @returns true if the user can delete the post
*/
export declare function canDeletePost(post: IPost, channel: IChannel, user?: IUser | IDiscussionsUser): boolean;
/**
* Parses mentioned users

@@ -25,0 +17,0 @@ * @param text A string to parse mentioned users from

{
"name": "@esri/hub-discussions",
"version": "25.4.1",
"version": "25.5.0",
"description": "Module to interact with ArcGIS Hub Discussions API in Node.js and modern browsers.",

@@ -5,0 +5,0 @@ "main": "dist/node/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc