109 lines
3.2 KiB
Dart
109 lines
3.2 KiB
Dart
// Dart port of PermissionResult types from old_repo/types/permissions.ts
|
|
|
|
import '../models/permission_update.dart';
|
|
|
|
export '../models/permission_update.dart' show PermissionRuleValue;
|
|
|
|
/// A specific permission rule that matched a command.
|
|
class PermissionRule {
|
|
final String behavior; // 'allow' | 'deny' | 'ask'
|
|
final PermissionRuleValue value;
|
|
final String source; // 'localSettings' | 'session' | 'userSettings' | 'builtin'
|
|
|
|
const PermissionRule({
|
|
required this.behavior,
|
|
required this.value,
|
|
this.source = 'localSettings',
|
|
});
|
|
}
|
|
|
|
/// Why a permission decision was made.
|
|
class PermissionDecisionReason {
|
|
final String type; // 'rule'|'mode'|'other'|'classifier'|'workingDir'|...
|
|
final PermissionRule? rule;
|
|
final String? mode;
|
|
final String? reason;
|
|
final String? classifier;
|
|
|
|
const PermissionDecisionReason({
|
|
required this.type,
|
|
this.rule,
|
|
this.mode,
|
|
this.reason,
|
|
this.classifier,
|
|
});
|
|
|
|
factory PermissionDecisionReason.rule(PermissionRule rule) =>
|
|
PermissionDecisionReason(type: 'rule', rule: rule);
|
|
|
|
factory PermissionDecisionReason.mode(String mode) =>
|
|
PermissionDecisionReason(type: 'mode', mode: mode);
|
|
|
|
factory PermissionDecisionReason.other(String reason) =>
|
|
PermissionDecisionReason(type: 'other', reason: reason);
|
|
}
|
|
|
|
/// The result of a permission check.
|
|
class PermissionResult {
|
|
final String behavior; // 'allow' | 'ask' | 'deny' | 'passthrough'
|
|
final String? message;
|
|
final Map<String, dynamic>? updatedInput;
|
|
final PermissionDecisionReason? decisionReason;
|
|
final List<PermissionUpdate>? suggestions;
|
|
final String? blockedPath;
|
|
|
|
// For 'ask' results triggered by legacy misparsing security check
|
|
final bool isBashSecurityCheckForMisparsing;
|
|
|
|
const PermissionResult({
|
|
required this.behavior,
|
|
this.message,
|
|
this.updatedInput,
|
|
this.decisionReason,
|
|
this.suggestions,
|
|
this.blockedPath,
|
|
this.isBashSecurityCheckForMisparsing = false,
|
|
});
|
|
|
|
const PermissionResult.passthrough({String? message})
|
|
: behavior = 'passthrough',
|
|
message = message,
|
|
updatedInput = null,
|
|
decisionReason = null,
|
|
suggestions = null,
|
|
blockedPath = null,
|
|
isBashSecurityCheckForMisparsing = false;
|
|
|
|
factory PermissionResult.allow({
|
|
Map<String, dynamic>? updatedInput,
|
|
PermissionDecisionReason? decisionReason,
|
|
}) => PermissionResult(
|
|
behavior: 'allow',
|
|
updatedInput: updatedInput,
|
|
decisionReason: decisionReason,
|
|
);
|
|
|
|
factory PermissionResult.deny({
|
|
required String message,
|
|
required PermissionDecisionReason decisionReason,
|
|
}) => PermissionResult(
|
|
behavior: 'deny',
|
|
message: message,
|
|
decisionReason: decisionReason,
|
|
);
|
|
|
|
factory PermissionResult.ask({
|
|
required String message,
|
|
PermissionDecisionReason? decisionReason,
|
|
List<PermissionUpdate>? suggestions,
|
|
String? blockedPath,
|
|
bool isBashSecurityCheckForMisparsing = false,
|
|
}) => PermissionResult(
|
|
behavior: 'ask',
|
|
message: message,
|
|
decisionReason: decisionReason,
|
|
suggestions: suggestions,
|
|
blockedPath: blockedPath,
|
|
isBashSecurityCheckForMisparsing: isBashSecurityCheckForMisparsing,
|
|
);
|
|
}
|