Best JavaScript code snippet using mocha
AuthAPI.js
Source:AuthAPI.js
...209 }210 return refreshTokenPromise;211 }212 var isPermittedCreateConceptset = function() {213 return isPermitted('conceptset:post');214 }215 var isPermittedReadConceptsets = function () {216 return isPermitted('conceptset:get');217 };218 var isPermittedUpdateConceptset = function(conceptsetId) {219 return (isPermitted('conceptset:' + conceptsetId + ':put') && isPermitted('conceptset:' + conceptsetId + ':items:put')) || (isPermitted('conceptset:*:put') && isPermitted('conceptset:*:items:put'));220 };221 var isPermittedDeleteConceptset = function(id) {222 return isPermitted('conceptset:' + id + ':delete');223 };224 var isPermittedReadIRs = function () {225 return isPermitted('ir:get');226 };227 var isPermittedEditIR = function (id) {228 return isPermitted('ir:' + id + ':put');229 };230 var isPermittedCreateIR = function () {231 return isPermitted('ir:post');232 };233 var isPermittedDeleteIR = function(id) {234 return isPermitted('ir:' + id + ':delete');235 };236 var isPermittedCopyIR = function(id) {237 return isPermitted('ir:' + id + ':copy:get');238 };239 var isPermittedReadEstimations = function () {240 return isPermitted('comparativecohortanalysis:get');241 };242 var isPermittedEditSourcePriortiy = function() {243 return isPermitted('source:*:daimons:*:set-priority:post')244 };245 var isPermittedReadEstimation = function (id) {246 return isPermitted('comparativecohortanalysis:' + id + ':get');247 };248 var isPermittedCreateEstimation = function() {249 return isPermitted('comparativecohortanalysis:post');250 };251 const isPermittedDeleteEstimation = function(id) {252 return isPermitted(`comparativecohortanalysis:${id}:delete`);253 }254 var isPermittedReadPlps = function() {255 return isPermitted('plp:get');256 };257 var isPermittedCreatePlp = function () {258 return isPermitted('plp:post');259 };260 var isPermittedReadPlp = function(id) {261 return isPermitted('plp:' + id + ':get');262 };263 var isPermittedDeletePlp = function(id) {264 return isPermitted('plp:' + id + ':delete');265 };266 var isPermittedCopyPlp = function(id) {267 return isPermitted(`plp:${id}:copy:get`);268 }269 var isPermittedSearch = function() {270 return isPermitted('vocabulary:*:search:*:get');271 };272 var isPermittedViewCdmResults = function () {273 return isPermitted('cdmresults:*:get');274 };275 var isPermittedViewProfiles = function (sourceKey) {276 return isPermitted(`${sourceKey}:person:*:get`);277 };278 var isPermittedViewProfileDates = function() {279 return isPermitted('*:person:*:get:dates');280 };281 var isPermittedReadCohort = function(id) {282 return isPermitted('cohortdefinition:' + id + ':get') && isPermitted('cohortdefinition:sql:post');283 }284 var isPermittedReadCohorts = function() {285 return isPermitted('cohortdefinition:get');286 }287 var isPermittedCreateCohort = function() {288 return isPermitted('cohortdefinition:post');289 }290 var isPermittedCopyCohort = function(id) {291 return isPermitted('cohortdefinition:' + id + ':copy:get');292 }293 var isPermittedUpdateCohort = function(id) {294 var permission = 'cohortdefinition:' + id + ':put';295 return isPermitted(permission);296 }297 var isPermittedDeleteCohort = function(id) {298 var permission = 'cohortdefinition:' + id + ':delete';299 var allPermissions = 'cohortdefinition:delete';300 return isPermitted(permission) || isPermitted(allPermissions);301 }302 var isPermittedGenerateCohort = function(cohortId, sourceKey) {303 return isPermitted('cohortdefinition:' + cohortId + ':generate:' + sourceKey + ':get') &&304 isPermitted('cohortdefinition:' + cohortId + ':info:get');305 }306 var isPermittedReadCohortReport = function(cohortId, sourceKey) {307 return isPermitted('cohortdefinition:' + cohortId + ':report:' + sourceKey + ':get');308 }309 var isPermittedReadJobs = function() {310 return isPermitted('job:execution:get');311 }312 var isPermittedEditConfiguration = function() {313 return isPermitted('configuration:edit:ui')314 }315 var isPermittedCreateSource = function() {316 return isPermitted('source:post');317 }318 var isPermittedReadSource = function(key) {319 return isPermitted('source:' + key + ':get');320 }321 var isPermittedCheckSourceConnection = function(key) {322 return isPermitted('source:connection:' + key + ':get');323 }324 var isPermittedEditSource = function(key) {325 return isPermitted('source:' + key + ':put');326 }327 var isPermittedDeleteSource = function(key) {328 return isPermitted('source:' + key + ':delete');329 }330 var isPermittedReadRoles = function() {331 return isPermitted('role:get');332 }333 var isPermittedReadRole = function (roleId) {334 var permitted =335 isPermitted('role:' + roleId + ':get') &&336 isPermitted('permission:get') &&337 isPermitted('role:' + roleId + ':permissions:get') &&338 isPermitted('user:get') &&339 isPermitted('role:' + roleId + ':users:get');340 return permitted;341 }342 var isPermittedEditRole = function(roleId) {343 return isPermitted('role:' + roleId + ':put');344 }345 var isPermittedCreateRole = function() {346 return isPermitted('role:post');347 }348 var isPermittedDeleteRole = function(roleId) {349 return isPermitted('role:' + roleId + ':delete');350 }351 var isPermittedEditRoleUsers = function(roleId) {352 return isPermitted('role:' + roleId + ':users:*:put') && isPermitted('role:' + roleId + ':users:*:delete');353 }354 var isPermittedEditRolePermissions = function(roleId) {355 return isPermitted('role:' + roleId + ':permissions:*:put') && isPermitted('role:' + roleId + ':permissions:*:delete');356 }357 const isPermittedGetAllNotifications = function() {358 return isPermitted('notifications:get');359 };360 const isPermittedGetViewedNotifications = function() {361 return isPermitted('notifications:viewed:get');362 };363 const isPermittedPostViewedNotifications = function() {364 return isPermitted('notifications:viewed:post');365 };366 const isPermittedImportUsers = function() {367 return isPermitted('user:import:post') && isPermitted('user:import:*:post');368 }369 const hasSourceAccess = function (sourceKey) {370 return isPermitted(`source:${sourceKey}:access`) || /* For 2.5.* and below */ isPermitted(`cohortdefinition:*:generate:${sourceKey}:get`);371 }372 const isPermittedRunAs = () => isPermitted('user:runas:post');373 const setAuthParams = (tokenHeader, permissionsStr = '') => {374 !!tokenHeader && token(tokenHeader);375 !!permissionsStr && permissions(permissionsStr.split('|'));376 };377 var resetAuthParams = function () {378 token(null);379 subject(null);380 permissions(null);381 };382 const runAs = function(login, success, error) {383 return $.ajax({384 method: 'POST',385 url: config.webAPIRoot + 'user/runas',386 data: {...
Groups.js
Source:Groups.js
...66 *67 * @returns JSX68 */69 const renderTabs = () => {70 if (tab === 0 && isPermitted(user, ['BROWSE_GROUPS'])) {71 return (72 <KeyGroupList73 groups={groups}74 isEditor={isPermitted(user, ['EDIT_GROUP'])}75 onOpenList={(object) => setOpenKeyList({ dialog: 'GROUP', object })}76 onEdit={(id) => setOpenCreateDialog({ dialog: 'GROUP', id })}77 />78 );79 }80 if (tab === 1 && isPermitted(user, ['BROWSE_COLLECTIONS'])) {81 return (82 <CollectionList83 collections={collections}84 isEditor={isPermitted(user, ['EDIT_COLLECTION'])}85 onOpenList={(object) => setOpenKeyList({ dialog: 'COLLECTION', object })}86 onEdit={(id) => setOpenCreateDialog({ dialog: 'COLLECTION', id })}87 />88 );89 }90 return null;91 };92 /**93 * Render tab bar94 *95 * @returns JSX96 */97 const renderBar = () => (98 <AppBar99 position="relative"100 className="my-6"101 color="default"102 >103 <Tabs104 value={tab}105 onChange={(e, val) => setTab(val)}106 aria-label="group and collection tabs"107 >108 <Tab109 label={language.dictionary.labelKeyGroups}110 disabled={!isPermitted(user, ['BROWSE_GROUPS'])}111 />112 <Tab113 label={language.dictionary.labelCollections}114 disabled={!isPermitted(user, ['BROWSE_COLLECTIONS'])}115 />116 </Tabs>117 </AppBar>118 );119 /**120 * Render dialogs121 *122 * @returns JSX123 */124 const renderDialogs = () => (125 <>126 {openCreateDialog && openCreateDialog.dialog === 'GROUP' && (127 <CreateKeyGroup128 openDialog={openCreateDialog && openCreateDialog.dialog === 'GROUP'}129 groups={groups}130 id={openCreateDialog && openCreateDialog.id}131 onClose={(unsaved) => handleCloseDialog(unsaved)}132 onCreated={() => setGroups(undefined)}133 />134 )}135 {openCreateDialog && openCreateDialog.dialog === 'COLLECTION' && (136 <CreateCollection137 openDialog={openCreateDialog && openCreateDialog.dialog === 'COLLECTION'}138 collections={collections}139 id={openCreateDialog && openCreateDialog.id}140 onClose={(unsaved) => handleCloseDialog(unsaved)}141 onCreated={() => setCollections(undefined)}142 />143 )}144 {openKeyList && openKeyList.dialog === 'GROUP' && (145 <GroupKeys146 openDialog={openKeyList.dialog === 'GROUP'}147 group={openKeyList.object}148 onClose={() => setOpenKeyList(undefined)}149 />150 )}151 {openKeyList && openKeyList.dialog === 'COLLECTION' && (152 <AddToCollection153 openDialog={openKeyList.dialog === 'COLLECTION'}154 collection={openKeyList.object}155 isEditor={isPermitted(user, ['EDIT_COLLECTION'])}156 onClose={() => setOpenKeyList(undefined)}157 />158 )}159 <UnsavedChanges160 openDialog={openUnsavedDialog}161 onClose={() => setOpenUnsavedDialog(false)}162 onConfirm={() => setOpenCreateDialog(undefined)}163 />164 </>165 );166 const renderCreateButton = () => {167 let label;168 if (tab === 0) {169 if (!isPermitted(user, ['CREATE_GROUP']) && !isPermitted(user, ['EDIT_GROUP'])) {170 label = language.dictionary.notChangeGroup;171 } else if (!isPermitted(user, ['CREATE_GROUP'])) {172 label = language.dictionary.notCreateGroup;173 } else if (!isPermitted(user, ['EDIT_GROUP'])) {174 label = language.dictionary.notEditGroup;175 }176 } else if (tab === 1) {177 if (!isPermitted(user, ['CREATE_COLLECTION']) && !isPermitted(user, ['EDIT_COLLECTION'])) {178 label = language.dictionary.notChangeCollection;179 } else if (!isPermitted(user, ['CREATE_COLLECTION'])) {180 label = language.dictionary.notCreateCollection;181 } else if (!isPermitted(user, ['EDIT_COLLECTION'])) {182 label = language.dictionary.notEditCollection;183 }184 }185 return (186 <>187 <ActionButton188 label={tab === 0189 ? language.dictionary.newKeyGroup : language.dictionary.newCollection}190 icon={<Add />}191 onClick={() => setOpenCreateDialog({ dialog: tab === 0 ? 'GROUP' : 'COLLECTION' })}192 disabled={(tab === 0 && !isPermitted(user, ['CREATE_GROUP']))193 || (tab === 1 && !isPermitted(user, ['CREATE_COLLECTION']))}194 />195 <MissingPermission196 show={label}197 label={label}198 />199 </>200 );201 };202 return (203 <div className="py-14 md:w-10/12 m-auto pb-28">204 <p className="px-2 mt-20 lg:mt-6">{language.dictionary.sectionGroupsCollections}</p>205 {renderBar()}206 {renderCreateButton()}207 {renderTabs()}...
api.js
Source:api.js
...35 get: {36 // TODO: write the get action() method37 authRequired,38 action() {39 if (isPermitted(this.user, "admin") ||40 isPermitted(this.user, "guest") ||41 isPermitted(this.user, "owner")) {42 // Collection.findOne(this.urlParams.id).fetch();43 const records = Collection.findOne({ _id: this.urlParams.id });44 if (!records) {45 return {46 statusCode: 404,47 status: "fail",48 message: "Record does not exist"49 };50 }51 return {52 statusCode: 200,53 status: "success",54 data: records55 };56 }57 }58 },59 post: {60 // TODO: write the post action() method61 authRequired,62 action() {63 if (!(isPermitted(this.user, "admin")) ||64 isPermitted(this.user, "owner")) {65 return {66 statusCode: 401,67 status: "fail",68 message: "you do not have permission to add a record"69 };70 }71 if (isPermitted(this.user, "admin") ||72 isPermitted(this.user, "owner")) {73 const insertedData = Collection.insert(this.bodyParams);74 if (!insertedData) {75 return {76 statusCode: 400,77 status: "fail",78 message: "Record Creation was not succesful"79 };80 }81 return {82 statusCode: 201,83 status: "success",84 data: insertedData85 };86 }87 }88 },89 put: {90 // TODO: write the put action() method91 authRequired,92 action() {93 if (!(isPermitted(this.user, "admin")) ||94 isPermitted(this.user, "owner")) {95 return {96 statusCode: 401,97 status: "fail",98 message: "you do not have permission to edit this record"99 };100 }101 if (isPermitted(this.user, "admin") ||102 isPermitted(this.user, "owner")) {103 const update = Collection.upsert({104 _id: this.urlParams.id105 }, {106 $set: this.bodyParams107 });108 if (!update) {109 return {110 statusCode: 404,111 status: "fail",112 message: "Record does not exist"113 };114 }115 const record = Collection.findOne(this.urlParams.id);116 return {117 statusCode: 200,118 status: "success",119 data: update, record120 };121 }122 }123 },124 delete: {125 // TODO: write the delete action() method126 authRequired,127 action() {128 if (!(isPermitted(this.user, "admin")) ||129 isPermitted(this.user, "owner")) {130 return {131 statusCode: 401,132 status: "fail",133 message: "you do not have permission to delete a record"134 };135 }136 if (isPermitted(this.user, "admin") ||137 isPermitted(this.user, "owner")) {138 if (Collection._name === "Products") {139 const item = Collection.findOne(this.urlParams.id);140 item.isDeleted = true;141 const updatedCollection = Collection.upsert({ _id: this.urlParams.id }, {142 $set: item143 });144 return {145 statusCode: 204,146 status: "success",147 message: "Product is archived",148 data: updatedCollection149 };150 }151 const updatedCollection = Collection.remove({_id: this.urlParams.id });...
PermissionsMixin.test.js
Source:PermissionsMixin.test.js
...18const { isPermitted, isAnyPermitted } = PermissionsMixin;19describe('PermissionsMixin', () => {20 describe('isPermitted', () => {21 it('returns `true` when required permissions are `undefined`', () => {22 expect(isPermitted([], undefined)).toBeTruthy();23 });24 it('returns `true` when required permissions are empty list', () => {25 expect(isPermitted([], [])).toBeTruthy();26 });27 it('returns `false` when possessed permissions are `undefined` and required permissions are empty', () => {28 expect(isPermitted(undefined, ['foo'])).toBeFalsy();29 });30 it('returns `false` when possessed permissions are `undefined`', () => {31 expect(isPermitted(undefined, ['foo'])).toBeFalsy();32 });33 it('returns `true` when wildcard permission is possessed', () => {34 expect(isPermitted(['*'], undefined)).toBeTruthy();35 expect(isPermitted(['*'], [])).toBeTruthy();36 expect(isPermitted(['*'], ['foo'])).toBeTruthy();37 expect(isPermitted(['*'], ['foo', 'bar'])).toBeTruthy();38 });39 it('returns `true` when possessed are identical to required permissions', () => {40 expect(isPermitted(['foo'], ['foo'])).toBeTruthy();41 expect(isPermitted(['foo', 'bar'], ['foo', 'bar'])).toBeTruthy();42 expect(isPermitted(['bar', 'foo'], ['foo', 'bar'])).toBeTruthy();43 });44 it('returns `true` when possessed contain all required permissions', () => {45 expect(isPermitted(['foo', 'bar'], ['foo'])).toBeTruthy();46 expect(isPermitted(['foo', 'bar', 'baz'], ['foo', 'bar'])).toBeTruthy();47 expect(isPermitted(['bar', 'baz', 'foo'], ['foo', 'bar'])).toBeTruthy();48 });49 it('returns `false` when possessed do not contain all required permissions', () => {50 expect(isPermitted(['foo'], ['foo', 'bar'])).toBeFalsy();51 expect(isPermitted(['foo', 'bar'], ['foo', 'bar', 'baz'])).toBeFalsy();52 expect(isPermitted(['bar', 'foo'], ['foo', 'bar', 'baz'])).toBeFalsy();53 });54 });55 describe('isAnyPermitted', () => {56 it('returns `true` when required permissions are `undefined`', () => {57 expect(isAnyPermitted([], undefined)).toBeTruthy();58 });59 it('returns `true` when required permissions are empty list', () => {60 expect(isAnyPermitted([], [])).toBeTruthy();61 });62 it('returns `false` when possessed permissions are `undefined` and required permissions are empty', () => {63 expect(isAnyPermitted(undefined, ['foo'])).toBeFalsy();64 });65 it('returns `false` when possessed permissions are `undefined`', () => {66 expect(isAnyPermitted(undefined, ['foo'])).toBeFalsy();...
endpoints.js
Source:endpoints.js
...19 } else {20 res.sendJSONStatus(res, consts.HTTP_UNAUTHORIZED, 'Unauthorized', 'Invalid/Missing');21 }22 });23 endpoints.get('/permissions', authorization.isPermitted('admin:api:permissions:read'), function getSubjects (req, res) {24 res.json(authorization.seenPermissions);25 });26 endpoints.get('/permissions/trie', authorization.isPermitted('admin:api:permissions:read'), function getSubjects (req, res) {27 res.json(authorization.expandedPermissions());28 });29 endpoints.get('/subjects', authorization.isPermitted('admin:api:subjects:read'), function getSubjects (req, res) {30 res.json(_.map(authorization.storage.subjects, function eachSubject (subject) {31 return _.pick(subject, ['_id', 'name', 'accessToken', 'roles']);32 }));33 });34 endpoints.post('/subjects', authorization.isPermitted('admin:api:subjects:create'), function createSubject (req, res) {35 authorization.storage.createSubject(req.body, function created (err, created) {36 if (err) {37 res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);38 } else {39 res.json(created);40 }41 });42 });43 endpoints.put('/subjects', authorization.isPermitted('admin:api:subjects:update'), function saveSubject (req, res) {44 authorization.storage.saveSubject(req.body, function saved (err, saved) {45 if (err) {46 res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);47 } else {48 res.json(saved);49 }50 });51 });52 endpoints.delete('/subjects/:_id', authorization.isPermitted('admin:api:subjects:delete'), function deleteSubject (req, res) {53 authorization.storage.removeSubject(req.params._id, function deleted (err) {54 if (err) {55 res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);56 } else {57 res.json({ });58 }59 });60 });61 endpoints.get('/roles', authorization.isPermitted('admin:api:roles:list'), function getRoles (req, res) {62 res.json(authorization.storage.roles);63 });64 endpoints.post('/roles', authorization.isPermitted('admin:api:roles:create'), function createSubject (req, res) {65 authorization.storage.createRole(req.body, function created (err, created) {66 if (err) {67 res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);68 } else {69 res.json(created);70 }71 });72 });73 endpoints.put('/roles', authorization.isPermitted('admin:api:roles:update'), function saveRole (req, res) {74 authorization.storage.saveRole(req.body, function saved (err, saved) {75 if (err) {76 res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);77 } else {78 res.json(saved);79 }80 });81 });82 endpoints.delete('/roles/:_id', authorization.isPermitted('admin:api:roles:delete'), function deleteRole (req, res) {83 authorization.storage.removeRole(req.params._id, function deleted (err) {84 if (err) {85 res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);86 } else {87 res.json({ });88 }89 });90 });91 endpoints.get('/debug/check/:permission', function check (req, res, next) {92 authorization.isPermitted(req.params.permission)(req, res, next);93 }, function debug (req, res) {94 res.json({check: true});95 });96 return endpoints;97}...
PermissionService.js
Source:PermissionService.js
...3], function (4 AuthAPI,5) {6 function isPermittedCreateCC() {7 return AuthAPI.isPermitted(`cohort-characterization:post`);8 }9 function isPermittedImportCC() {10 return AuthAPI.isPermitted(`cohort-characterization:import:post`);11 }12 function isPermittedGetCCList() {13 return AuthAPI.isPermitted(`cohort-characterization:get`);14 }15 function isPermittedGetCC(id) {16 return AuthAPI.isPermitted(`cohort-characterization:${id}:get`);17 }18 function isPermittedUpdateCC(id) {19 return AuthAPI.isPermitted(`cohort-characterization:${id}:put`);20 }21 function isPermittedDeleteCC(id) {22 return AuthAPI.isPermitted(`cohort-characterization:${id}:delete`);23 }24 function isPermittedGetCCGenerations(id) {25 return AuthAPI.isPermitted(`cohort-characterization:${id}:generation:get`);26 }27 function isPermittedGenerateCC(id, sourceKey) {28 return AuthAPI.isPermitted(`cohort-characterization:${id}:generation:${sourceKey}:post`);29 }30 function isPermittedGetCCGenerationResults(sourceKey) {31 return AuthAPI.isPermitted(`cohort-characterization:generation:*:result:get`) && AuthAPI.isPermitted(`source:${sourceKey}:access`);32 }33 function isPermittedExportGenerationDesign(id) {34 return AuthAPI.isPermitted(`cohort-characterization:generation:${id}:design:get`);35 }36 function isPermittedExportCC(id) {37 return AuthAPI.isPermitted(`cohort-characterization:${id}:export:get`);38 }39 function isPermittedCopyCC(id) {40 return AuthAPI.isPermitted(`cohort-characterization:${id}:post`);41 }42 //43 function isPermittedGetFaList() {44 return AuthAPI.isPermitted(`feature-analysis:get`);45 }46 function isPermittedCreateFa() {47 return AuthAPI.isPermitted(`feature-analysis:post`);48 }49 function isPermittedGetFa(id) {50 return AuthAPI.isPermitted(`feature-analysis:${id}:get`);51 }52 function isPermittedUpdateFa(id) {53 return AuthAPI.isPermitted(`feature-analysis:${id}:put`);54 }55 function isPermittedDeleteFa(id) {56 return AuthAPI.isPermitted(`feature-analysis:${id}:delete`);57 }58 return {59 isPermittedCreateCC,60 isPermittedImportCC,61 isPermittedGetCCList,62 isPermittedGetCC,63 isPermittedUpdateCC,64 isPermittedDeleteCC,65 isPermittedGetCCGenerations,66 isPermittedGenerateCC,67 isPermittedGetCCGenerationResults,68 isPermittedExportGenerationDesign,69 isPermittedExportCC,70 isPermittedCopyCC,...
PermissionsTest.js
Source:PermissionsTest.js
...9 describe('Permissions.considerPermissions', function() {10 it('should work as expected', function() {11 var claim = Permissions.considerPermissions('resource1', 'resource2:action');12 expect(claim.isPermitted).to.be.a('function');13 expect(claim.isPermitted('resource1')).to.be.true;14 expect(claim.isPermitted('resource1:action')).to.be.true;15 expect(claim.isPermitted('resource2')).to.be.false;16 expect(claim.isPermitted('resource2:action')).to.be.true;17 });18 });19 describe('Permissions.considerSubject', function() {20 it('should work as expected', function() {21 var claim = Permissions.considerSubject({22 permissions : ['resource1', 'resource2:action']23 });24 expect(claim.isPermitted).to.be.a('function');25 expect(claim.isPermitted('resource1')).to.be.true;26 expect(claim.isPermitted('resource1:action')).to.be.true;27 expect(claim.isPermitted('resource2')).to.be.false;28 expect(claim.isPermitted('resource2:action')).to.be.true;29 expect(claim.isPermitted('resource1:action', 'resource2:action')).to.be.true;30 expect(claim.isPermitted(['resource1:action', 'resource2:action'])).to.be.true;31 });32 });33 describe('Permissions.coalescePermissions', function() {34 it('should work as expected', function() {35 var result;36 (function() {37 result = Permissions.coalescePermissions([[arguments, 6], 7,[[8]]]);38 })(1, 2, 3, 4, 5)39 expect(result).to.have.lengthOf(8);40 });41 });...
permissible.js
Source:permissible.js
1/*globals SCUI */2/** 3 A mixin to render unauthorized items differently (e.g., change background color or draw a lock icon).4 This is used to differentiate items that are disabled owing to permission issues).5 6 A user of this mixin must set the binding to the 'isPermitted' property.7 When 'isPermitted' is false, the class 'unauthorized' is added.8 9 @author Suvajit Gupta10*/11SCUI.Permissible = {12 13 isPermitted: null,14 isPermittedBindingDefault: SC.Binding.oneWay().bool(),15 displayProperties: ['isPermitted', 'tooltipSuffix'],16 17 /**18 @optional19 What to append to the tooltip when unauthorized20 */21 tooltipSuffix: "(unauthorized)".loc(),22 23 _isPermittedDidChange: function() {24 if(this.get('isPermitted')) {25 if(!SC.none(this._tooltip)) this.setIfChanged('toolTip', this._tooltip);26 }27 else {28 this._tooltip = this.get('toolTip');29 this.set('toolTip', (!(SC.none(this._tooltip)) ? (this._toolTip + " ") : "") + this.get('tooltipSuffix'));30 }31 }.observes('isPermitted'),32 renderMixin: function(context, firstTime) {33 context.setClass('unauthorized', !this.get('isPermitted'));34 }35 ...
Using AI Code Generation
1var mocha = require('mocha');2var mocha = require('mocha');3var mocha = require('mocha');4var mocha = require('mocha');5var mocha = require('mocha');6var mocha = require('mocha');7var mocha = require('mocha');8var mocha = require('mocha');9var mocha = require('mocha');
Using AI Code Generation
1var assert = require('assert');2var mocha = require('mocha');3var isPermitted = mocha.isPermitted;4describe('isPermitted', function() {5 it('should return true for a permitted user', function() {6 assert.equal(isPermitted('foo'), true);7 });8 it('should return false for a non-permitted user', function() {9 assert.equal(isPermitted('bar'), false);10 });11});12 mocha.setup('bdd');13 mocha.run();14var assert = require('assert');15var mocha = require('mocha');16var isPermitted = mocha.isPermitted;17describe('isPermitted', function() {18 it('should return true for a permitted user', function() {19 assert.equal(isPermitted('foo'), true);20 });21 it('should return false for a non-permitted user', function() {22 assert.equal(isPermitted('bar'), false);23 });24});25 mocha.setup('bdd');26 mocha.run();27var assert = require('assert');28var mocha = require('mocha');
Using AI Code Generation
1var mocha = new Mocha();2if(mocha.isPermitted()){3} else {4}5var mocha = new Mocha();6mocha.isPermitted(function(err, result){7 if(err){8 } else {9 if(result){10 } else {11 }12 }13});14var mocha = new Mocha();15mocha.isPermitted()16 .then(function(result){17 if(result){18 } else {19 }20 })21 .catch(function(err){22 });23var mocha = new Mocha();24mocha.isPermitted()25 .then(function(result){26 if(result){27 } else {28 }29 })30 .catch(function(err){31 });32var mocha = new Mocha();33mocha.isPermitted()34 .then(function(result){35 if(result){36 } else {37 }38 })39 .catch(function(err){40 });41var mocha = new Mocha();42mocha.isPermitted()43 .then(function(result){44 if(result){45 } else {46 }47 })48 .catch(function(err){49 });50var mocha = new Mocha();51mocha.isPermitted()52 .then(function(result){53 if(result){54 } else {55 }56 })57 .catch(function(err){58 });
Using AI Code Generation
1var Mocha = require('mocha');2var mocha = new Mocha({});3mocha.addFile('tests/firstTest.js');4mocha.run(function(failures){5 process.on('exit', function () {6 });7});8var assert = require('assert');9var isPermitted = require('../isPermitted');10describe('isPermitted', function() {11 it('should return true if user is permitted to access the resource', function() {12 assert.equal(true, isPermitted('admin', 'read'));13 });14 it('should return false if user is not permitted to access the resource', function() {15 assert.equal(false, isPermitted('admin', 'delete'));16 });17});18module.exports = function(user, resource) {19 if(user === 'admin' && resource === 'read') {20 return true;21 }22 return false;23};
Using AI Code Generation
1var mocha = new Mocha();2var isPermitted = mocha.isPermitted('test');3var mocha = new Mocha();4var isPermitted = mocha.isPermitted('test');5var mocha = new Mocha();6var isPermitted = mocha.isPermitted('test');7var mocha = new Mocha();8var isPermitted = mocha.isPermitted('test');9var mocha = new Mocha();10var isPermitted = mocha.isPermitted('test');11var mocha = new Mocha();12var isPermitted = mocha.isPermitted('test');13var mocha = new Mocha();14var isPermitted = mocha.isPermitted('test');15var mocha = new Mocha();16var isPermitted = mocha.isPermitted('test');17var mocha = new Mocha();18var isPermitted = mocha.isPermitted('test');19var mocha = new Mocha();20var isPermitted = mocha.isPermitted('test');
Using AI Code Generation
1describe('Test suite', function() {2 it('Test case', function() {3 if (mocha.isPermitted('test')) {4 }5 });6});7describe('Test suite', function() {8 it('Test case', function() {9 if (mocha.isPermitted('test')) {10 }11 });12});13describe('Test suite', function() {14 it('Test case', function() {15 if (mocha.isPermitted('test')) {16 }17 });18});19describe('Test suite', function() {20 it('Test case', function() {21 if (mocha.isPermitted('test')) {22 }23 });24});25describe('Test suite', function() {26 it('Test case', function() {27 if (mocha.isPermitted('test')) {28 }29 });30});31describe('Test suite', function() {32 it('Test case', function() {33 if (mocha.isPermitted('test')) {34 }35 });36});37describe('Test suite', function() {38 it('Test case', function() {39 if (mocha.isPermitted('test')) {40 }41 });42});43describe('Test suite', function() {44 it('Test case', function() {45 if (mocha.isPermitted('test')) {46 }47 });48});49describe('Test suite', function() {50 it('Test case', function() {51 if (mocha.isPermitted('test')) {52 }53 });54});
Using AI Code Generation
1app.get('/page', function (req, res) {2 if (isPermitted(req.user, 'page')) {3 res.redirect('/page');4 } else {5 res.redirect('/login');6 }7});8app.get('/page', function (req, res) {9 if (isPermitted(req.user, 'page')) {10 res.redirect('/page');11 } else {12 res.redirect('/login');13 }14});15app.get('/page', function (req, res) {16 if (isPermitted(req.user, 'page')) {17 res.redirect('/page');18 } else {19 res.redirect('/login');20 }21});22app.get('/page', function (req, res) {23 if (isPermitted(req.user, 'page')) {24 res.redirect('/page');25 } else {26 res.redirect('/login');27 }28});29app.get('/page', function (req, res) {30 if (isPermitted(req.user, 'page'))
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!