{"record":{"id":"2b3f5991b10591eb","repo":"RocketChat/Rocket.Chat","slug":"error-not-authorized-2b3f59","errorCode":"error-not-authorized","errorMessage":"Not authorized","messagePattern":"Not authorized","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/slashcommands/archiveroom/server.ts","lineNumber":56,"sourceCode":"\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'archiveRoom' });\n\t\t}\n\n\t\tif (!room) {\n\t\t\tvoid api.broadcast('notify.ephemeralMessage', userId, message.rid, {\n\t\t\t\tmsg: i18n.t('Channel_doesnt_exist', {\n\t\t\t\t\tchannelName: channel,\n\t\t\t\t\tlng: settings.get('Language') || 'en',\n\t\t\t\t}),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tif (!(await roomCoordinator.getRoomDirectives(room.t).allowMemberAction(room, RoomMemberActions.ARCHIVE, userId))) {\n\t\t\tthrow new Meteor.Error('error-room-type-not-archivable', `Room type: ${room.t} can not be archived`);\n\t\t}\n\n\t\tif (!(await hasPermissionAsync(userId, 'archive-room', room._id))) {\n\t\t\tthrow new Meteor.Error('error-not-authorized', 'Not authorized');\n\t\t}\n\n\t\tif (room.archived) {\n\t\t\tvoid api.broadcast('notify.ephemeralMessage', userId, message.rid, {\n\t\t\t\tmsg: i18n.t('Duplicate_archived_channel_name', {\n\t\t\t\t\tchannelName: channel,\n\t\t\t\t\tlng: settings.get('Language') || 'en',\n\t\t\t\t}),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tawait archiveRoom(room._id, user);\n\n\t\tvoid api.broadcast('notify.ephemeralMessage', userId, message.rid, {\n\t\t\tmsg: i18n.t('Channel_Archived', {\n\t\t\t\tchannelName: channel,\n\t\t\t\tlng: settings.get('Language') || 'en',","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/slashcommands/archiveroom/server.ts#L38-L74","documentation":"After the room-type check, /archive verifies hasPermissionAsync(userId, 'archive-room', room._id). The permission is scope-aware: the user must hold archive-room either globally or on that specific room. Otherwise the command throws 'error-not-authorized' and nothing is archived.","triggerScenarios":"A regular member (non-owner, non-moderator, or a role without archive-room) running /archive in a channel; room-scoped permissions granted on other rooms but not this one; permission sets changed after a role restructuring.","commonSituations":"Workspaces where only admins hold archive-room; users assuming channel owners can archive by default (only if their role grants the permission); custom roles created without archive-room.","solutions":["Grant the archive-room permission to the user's role (Administration > Permissions), globally or scoped to the room","Ask a user who already holds the permission (typically an admin) to run /archive","For room-scoped setups, add the room-scoped archive-room permission for that leader or moderator on the specific room","Retry the command after the permission change propagates"],"exampleFix":"// before\nrunSlashCommand('/archive', { rid }); // from member without archive-room -> error-not-authorized\n\n// after\nif (!(await hasPermissionAsync(userId, 'archive-room', room._id))) {\n\treturn notifyUser('You need the archive-room permission to archive this channel');\n}\nrunSlashCommand('/archive', { rid });","handlingStrategy":"validation","validationCode":"if (!(await hasPermissionAsync(userId, 'archive-room', room._id))) {\n\treturn notifyUser('You need the archive-room permission to archive this channel');\n}\nrunCommand('/archive', room);","typeGuard":null,"tryCatchPattern":"catch (err) {\n\tif (err instanceof Meteor.Error && err.error === 'error-not-authorized') {\n\t\t// suggest contacting an admin or a user holding archive-room\n\t} else throw err;\n}","preventionTips":["Grant archive-room to the moderator or owner roles that should archive channels","Check both global and room-scoped permission before showing archive actions","Keep permission changes audited so refusals are explainable"],"tags":["slash-command","permissions","authorization","archive","rooms"],"backgroundTag":"permission-denied","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}