mdata 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb30d8e4bfb780f9646c13b55283838aec62116b
4
- data.tar.gz: 131491a48e2859fdcb9fd6fe069258b987996542
3
+ metadata.gz: faff685b0e5287c5c54d944f31011ca28d113241
4
+ data.tar.gz: 12e1cfd3508ba85da9372d305202c1af962c7a7c
5
5
  SHA512:
6
- metadata.gz: 1ba3b975c4f20280b21234a5ca2c447bb7c43350d0ca0752fe73306d5fb99e0da34d7b02d039242ba8306008182b56786eab68cf29132f840b5b7063955c2eae
7
- data.tar.gz: 0bc5a2faf3395705495289ac1a9816ea8d19023d6c1a0ceb18b3af8ef00b83d13726bed29baa3d2e198eda559177ed2482c441332125ede84a69b35f73b15b4b
6
+ metadata.gz: 0ef8902458d53e2c807f321417cf88d0cfe167602c248fe22efc26e534015688b36805f9f85204109cb5377eb1dbec58d5292d5d151e6387db0e03fc125a2446
7
+ data.tar.gz: 4b63b2a5e5dc49d42946ae6d2a1cc2cce2cdf22929d977c51fb762d952c64b13845c1d9a4ecae4c9f6a0b07c1bbbce362f8f0a82ce165b0a9fd4cce782264699
data/bin/mdata CHANGED
@@ -5,7 +5,7 @@ require 'commander/import'
5
5
  require 'mdata/metadata'
6
6
  require 'terminal-table'
7
7
 
8
- program :version, '1.1.0'
8
+ program :version, '1.2.0'
9
9
  program :description, 'Your Salesforce metadata navigator and manipulator'
10
10
  program :help, 'Author', 'Ben Burwell <ben.burwell@trifecta.com>'
11
11
 
@@ -385,6 +385,274 @@ command :'profile classAccess:copy' do |c|
385
385
  end
386
386
  end
387
387
 
388
+ command :'profile objectPermissions:read' do |c|
389
+ c.syntax = 'mdata profile objectPermissions:read --profile PROFILE [options]'
390
+ c.summary = 'Read object permissions from a profile'
391
+ c.option '--profile PROFILE', String, 'The profile to examine'
392
+ c.option '--object OBJECT', String, 'Optionally, an object to look for'
393
+ c.action do |args, opts|
394
+ begin
395
+ raise ArgumentError, 'no profile specified' if opts.profile.nil?
396
+ profile = Salesforce::Metadata::Profile.read opts.profile, opts.dir
397
+ profile.objectPermissions.keep_if { |x| x.object == opts.object } unless opts.object.nil?
398
+ profile.objectPermissions.sort! { |a, b| a.object <=> b.object }
399
+ rows = []
400
+ profile.objectPermissions.each do |fp|
401
+ rows << [ fp.object, fp.to_flag_style ]
402
+ end
403
+ table = Terminal::Table.new :rows => rows, :headings => ['Object', 'Permissions']
404
+ puts table
405
+ rescue ArgumentError => e
406
+ puts "Error executing command: #{e.message}"
407
+ end
408
+ end
409
+ end
410
+
411
+ # Profile - Object Permissions - Set
412
+ command :'profile objectPermissions:set' do |c|
413
+ c.syntax = 'mdata profile objectPermissions:set --profile PROFILE --object OBJECT [options]'
414
+ c.summary = 'Overwrites any existing permissions for the object on the profile with the ones specified'
415
+ c.option '--profile PROFILE', String, 'The profile to configure'
416
+ c.option '--object OBJECT', String, 'The object to assign permissions for'
417
+ c.option '--allowCreate', 'Set the allowCreate permission'
418
+ c.option '--allowEdit', 'Set the allowEdit permission'
419
+ c.option '--allowRead', 'Set the allowRead permission'
420
+ c.option '--allowDelete', 'Set the allowDelete permission'
421
+ c.option '--modifyAllRecords', 'Set the modifyAllRecords permission'
422
+ c.option '--viewAllRecords', 'Set the viewAllRecords permission'
423
+ c.action do |args, opts|
424
+ begin
425
+ raise ArgumentError, 'no profile specified' if opts.profile.nil?
426
+ raise ArgumentError, 'no object specified' if opts.object.nil?
427
+ profile = Salesforce::Metadata::Profile.read opts.profile, opts.dir
428
+ idx = profile.objectPermissions.find_index { |x| x.object == opts.object }
429
+
430
+ if idx.nil?
431
+ op = Salesforce::Types::ProfileObjectPermissions.new
432
+ op.object = opts.object
433
+ profile.objectPermissions.push op
434
+ idx = profile.objectPermissions.count - 1
435
+ end
436
+
437
+ profile.objectPermissions[idx].allowCreate = case opts.allowCreate
438
+ when nil then 'false'
439
+ else 'true'
440
+ end
441
+ profile.objectPermissions[idx].allowEdit = case opts.allowEdit
442
+ when nil then 'false'
443
+ else 'true'
444
+ end
445
+ profile.objectPermissions[idx].allowRead = case opts.allowRead
446
+ when nil then 'false'
447
+ else 'true'
448
+ end
449
+ profile.objectPermissions[idx].allowDelete = case opts.allowDelete
450
+ when nil then 'false'
451
+ else 'true'
452
+ end
453
+ profile.objectPermissions[idx].modifyAllRecords = case opts.modifyAllRecords
454
+ when nil then 'false'
455
+ else 'true'
456
+ end
457
+ profile.objectPermissions[idx].viewAllRecords = case opts.viewAllRecords
458
+ when nil then 'false'
459
+ else 'true'
460
+ end
461
+ profile.save
462
+ rescue ArgumentError => e
463
+ puts "Error executing command: #{e.message}"
464
+ end
465
+ end
466
+ end
467
+
468
+ # Profile - Object Permissions - Grant
469
+ command :'profile objectPermissions:grant' do |c|
470
+ c.syntax = 'mdata profile objectPermissions:grant --profile PROFILE --object OBJECT [options]'
471
+ c.summary = 'Grant permissions on an object to a profile'
472
+ c.option '--profile PROFILE', String, 'The profile to configure'
473
+ c.option '--object OBJECT', String, 'The object to assign permissions for'
474
+ c.option '--allowCreate', 'Grant the allowCreate permission'
475
+ c.option '--allowEdit', 'Grant the allowEdit permission'
476
+ c.option '--allowRead', 'Grant the allowRead permission'
477
+ c.option '--allowDelete', 'Grant the allowDelete permission'
478
+ c.option '--modifyAllRecords', 'Grant the modifyAllRecords permission'
479
+ c.option '--viewAllRecords', 'Grant the viewAllRecords permission'
480
+ c.action do |args, opts|
481
+ begin
482
+ raise ArgumentError, 'no profile specified' if opts.profile.nil?
483
+ raise ArgumentError, 'no object specified' if opts.object.nil?
484
+ profile = Salesforce::Metadata::Profile.read opts.profile, opts.dir
485
+ idx = profile.objectPermissions.find_index { |x| x.object == opts.object }
486
+
487
+ if idx.nil?
488
+ op = Salesforce::Types::ProfileObjectPermissions.new
489
+ op.object = opts.object
490
+ profile.objectPermissions.push op
491
+ idx = profile.objectPermissions.count - 1
492
+ end
493
+
494
+ profile.objectPermissions[idx].allowCreate = 'true' unless opts.allowCreate.nil?
495
+ profile.objectPermissions[idx].allowEdit = 'true' unless opts.allowEdit.nil?
496
+ profile.objectPermissions[idx].allowRead = 'true' unless opts.allowRead.nil?
497
+ profile.objectPermissions[idx].allowDelete = 'true' unless opts.allowDelete.nil?
498
+ profile.objectPermissions[idx].modifyAllRecords = 'true' unless opts.modifyAllRecords.nil?
499
+ profile.objectPermissions[idx].viewAllRecords = 'true' unless opts.viewAllRecords.nil?
500
+ profile.save
501
+ rescue ArgumentError => e
502
+ puts "Error executing command: #{e.message}"
503
+ end
504
+ end
505
+ end
506
+
507
+ # Profile - Object Permissions - Revoke
508
+ command :'profile objectPermissions:revoke' do |c|
509
+ c.syntax = 'mdata profile objectPermissions:revoke --profile PROFILE --object OBJECT [options]'
510
+ c.summary = 'Revoke permissions on an object from a profile'
511
+ c.option '--profile PROFILE', String, 'The profile to configure'
512
+ c.option '--object OBJECT', String, 'The object to assign permissions for'
513
+ c.option '--allowCreate', 'Revoke the allowCreate permission'
514
+ c.option '--allowEdit', 'Revoke the allowEdit permission'
515
+ c.option '--allowRead', 'Revoke the allowRead permission'
516
+ c.option '--allowDelete', 'Revoke the allowDelete permission'
517
+ c.option '--modifyAllRecords', 'Revoke the modifyAllRecords permission'
518
+ c.option '--viewAllRecords', 'Revoke the viewAllRecords permission'
519
+ c.action do |args, opts|
520
+ begin
521
+ raise ArgumentError, 'no profile specified' if opts.profile.nil?
522
+ raise ArgumentError, 'no object specified' if opts.object.nil?
523
+ profile = Salesforce::Metadata::Profile.read opts.profile, opts.dir
524
+ idx = profile.objectPermissions.find_index { |x| x.object == opts.object }
525
+
526
+ if idx.nil?
527
+ op = Salesforce::Types::ProfileObjectPermissions.new
528
+ op.object = opts.object
529
+ profile.objectPermissions.push op
530
+ idx = profile.objectPermissions.count - 1
531
+ end
532
+
533
+ profile.objectPermissions[idx].allowCreate = 'false' unless opts.allowCreate.nil?
534
+ profile.objectPermissions[idx].allowEdit = 'false' unless opts.allowEdit.nil?
535
+ profile.objectPermissions[idx].allowRead = 'false' unless opts.allowRead.nil?
536
+ profile.objectPermissions[idx].allowDelete = 'false' unless opts.allowDelete.nil?
537
+ profile.objectPermissions[idx].modifyAllRecords = 'false' unless opts.modifyAllRecords.nil?
538
+ profile.objectPermissions[idx].viewAllRecords = 'false' unless opts.viewAllRecords.nil?
539
+ profile.save
540
+ rescue ArgumentError => e
541
+ puts "Error executing command: #{e.message}"
542
+ end
543
+ end
544
+ end
545
+
546
+ # Profile - Object Permissions - Delete
547
+ command :'profile objectPermissions:delete' do |c|
548
+ c.syntax = 'mdata profile objectPermissions:delete --profile PROFILE --object OBJECT'
549
+ c.summary = 'Completely removes the permissions for a particular object. Useful if an object is deleted.'
550
+ c.option '--profile PROFILE', String, 'The profile to configure'
551
+ c.option '--object OBJECT', String, 'The object to delete permissions for'
552
+ c.action do |args, opts|
553
+ begin
554
+ raise ArgumentError, 'no profile specified' if opts.profile.nil?
555
+ raise ArgumentError, 'no object specified' if opts.object.nil?
556
+ profile = Salesforce::Metadata::Profile.read opts.profile, opts.dir
557
+ profile.objectPermissions.delete_if { |x| x.object == opts.object }
558
+ profile.save
559
+ rescue ArgumentError => e
560
+ puts "Error executing command: #{e.message}"
561
+ end
562
+ end
563
+ end
564
+
565
+ # Profile - Object Permissions - Copy
566
+ command :'profile objectPermissions:copy' do |c|
567
+ c.syntax = 'mdata profile objectPermissions:copy --fromProfile PROFILE --toProfile PROFILE --fromObject OBJECT --toObject OBJECT [options]'
568
+ c.summary = 'Copies the specified permissions for an object from one profile to another'
569
+ c.description = [
570
+ 'Copies the permissions on fromProfile for the object fromObject to toObject on toProfile.',
571
+ '',
572
+ 'If you are copying the permissions from one object to another on the same profile, you can use',
573
+ 'the --profile option rather than specifying the same --fromProfile and --toProfile.',
574
+ '',
575
+ 'Likewise, if you are copying the permissions for an object from one profile to another, you can',
576
+ 'specify an --object rather than a --fromObject and --toObject.'
577
+ ].join("\n")
578
+ c.option '--fromProfile PROFILE', String, 'The source profile'
579
+ c.option '--toProfile PROFILE', String, 'The destination profile'
580
+ c.option '--profile PROFILE', String, 'A profile to use as the source and destination'
581
+ c.option '--fromObject OBJECT', String, 'The source object'
582
+ c.option '--toObject OBJECT', String, 'The destination object'
583
+ c.option '--object OBJECT', String, 'An object to use as the source and destination'
584
+ c.option '--all', 'Copy all permissions'
585
+ c.option '--allowCreate', 'Copy the allowCreate permission'
586
+ c.option '--allowEdit', 'Copy the allowEdit permission'
587
+ c.option '--allowRead', 'Copy the allowRead permission'
588
+ c.option '--allowDelete', 'Copy the allowDelete permission'
589
+ c.option '--modifyAllRecords', 'Copy the modifyAllRecords permission'
590
+ c.option '--viewAllRecords', 'Copy the viewAllRecords permission'
591
+ c.action do |args, opts|
592
+ # Override options for helper options
593
+ opts.fromProfile = opts.profile if opts.profile
594
+ opts.toProfile = opts.profile if opts.profile
595
+ opts.fromObject = opts.object if opts.object
596
+ opts.toObject = opts.object if opts.object
597
+ opts.allowCreate = true if opts.all
598
+ opts.allowEdit = true if opts.all
599
+ opts.allowRead = true if opts.all
600
+ opts.allowDelete = true if opts.all
601
+ opts.modifyAllRecords = true if opts.all
602
+ opts.viewAllRecords = true if opts.all
603
+
604
+ begin
605
+ raise ArgumentError, 'no source profile specified' if opts.fromProfile.nil?
606
+ raise ArgumentError, 'no destination profile specified' if opts.toProfile.nil?
607
+ raise ArgumentError, 'no source object specified' if opts.fromObject.nil?
608
+ raise ArgumentError, 'no destination object specified' if opts.toObject.nil?
609
+
610
+ from_profile = Salesforce::Metadata::Profile.read opts.fromProfile, opts.dir
611
+ src_idx = from_profile.objectPermissions.find_index { |x| x.object == opts.fromObject }
612
+ raise ArgumentError, 'source object not found in source profile' if src_idx.nil?
613
+
614
+ to_profile = Salesforce::Metadata::Profile.read opts.toProfile, opts.dir
615
+ dst_idx = to_profile.objectPermissions.find_index { |x| x.object == opts.toObject }
616
+
617
+ if dst_idx.nil?
618
+ op = Salesforce::Types::ProfileObjectPermissions.new
619
+ op.object = opts.toObject
620
+ to_profile.objectPermissions.push op
621
+ dst_idx = to_profile.objectPermissions.count - 1
622
+ end
623
+
624
+ unless opts.allowCreate.nil?
625
+ val = from_profile.objectPermissions[src_idx].allowCreate
626
+ to_profile.objectPermissions[dst_idx].allowCreate = val
627
+ end
628
+ unless opts.allowEdit.nil?
629
+ val = from_profile.objectPermissions[src_idx].allowEdit
630
+ to_profile.objectPermissions[dst_idx].allowEdit = val
631
+ end
632
+ unless opts.allowRead.nil?
633
+ val = from_profile.objectPermissions[src_idx].allowRead
634
+ to_profile.objectPermissions[dst_idx].allowRead = val
635
+ end
636
+ unless opts.allowDelete.nil?
637
+ val = from_profile.objectPermissions[src_idx].allowDelete
638
+ to_profile.objectPermissions[dst_idx].allowDelete = val
639
+ end
640
+ unless opts.modifyAllRecords.nil?
641
+ val = from_profile.objectPermissions[src_idx].modifyAllRecords
642
+ to_profile.objectPermissions[dst_idx].modifyAllRecords = val
643
+ end
644
+ unless opts.viewAllRecords.nil?
645
+ val = from_profile.objectPermissions[src_idx].viewAllRecords
646
+ to_profile.objectPermissions[dst_idx].viewAllRecords = val
647
+ end
648
+
649
+ to_profile.save
650
+ rescue ArgumentError => e
651
+ puts "Error executing command: #{e.message}"
652
+ end
653
+ end
654
+ end
655
+
388
656
  alias_command :'pr fp:r', :'profile fieldPermissions:read'
389
657
  alias_command :'pr fp:s', :'profile fieldPermissions:set'
390
658
  alias_command :'pr fp:g', :'profile fieldPermissions:grant'
@@ -397,3 +665,10 @@ alias_command :'pr ca:g', :'profile classAccess:grant'
397
665
  alias_command :'pr ca:v', :'profile classAccess:revoke'
398
666
  alias_command :'pr ca:d', :'profile classAccess:delete'
399
667
  alias_command :'pr ca:c', :'profile classAccess:copy'
668
+
669
+ alias_command :'pr op:r', :'profile objectPermissions:read'
670
+ alias_command :'pr op:s', :'profile objectPermissions:set'
671
+ alias_command :'pr op:g', :'profile objectPermissions:grant'
672
+ alias_command :'pr op:v', :'profile objectPermissions:revoke'
673
+ alias_command :'pr op:c', :'profile objectPermissions:copy'
674
+ alias_command :'pr op:d', :'profile objectPermissions:delete'
@@ -16,6 +16,67 @@ module Salesforce
16
16
  xml_accessor :modifyAllRecords
17
17
  xml_accessor :object
18
18
  xml_accessor :viewAllRecords
19
+
20
+ # Get an array of granted permissions
21
+ #
22
+ # @return [Array] an array of strings, like ['allowCreate', 'allowRead']
23
+ def get_permissions
24
+ permissions = []
25
+ permissions.push 'allowCreate' if @allowCreate == 'true'
26
+ permissions.push 'allowDelete' if @allowDelete == 'true'
27
+ permissions.push 'allowEdit' if @allowEdit == 'true'
28
+ permissions.push 'allowRead' if @allowRead == 'true'
29
+ permissions.push 'modifyAllRecords' if @modifyAllRecords == 'true'
30
+ permissions.push 'viewAllRecords' if @viewAllRecords == 'true'
31
+ permissions
32
+ end
33
+
34
+ # A Unix flag style representation of the permissions, suitable for
35
+ # printing in a table
36
+ #
37
+ # @return [String] the granted permissions
38
+ def to_flag_style
39
+ permissions = ''
40
+
41
+ if @allowCreate
42
+ permissions += 'allowCreate '
43
+ else
44
+ permissions += ' '
45
+ end
46
+
47
+ if @allowDelete
48
+ permissions += 'allowDelete '
49
+ else
50
+ permissions += ' '
51
+ end
52
+
53
+ if @allowEdit
54
+ permissions += 'allowEdit '
55
+ else
56
+ permissions += ' '
57
+ end
58
+
59
+ if @allowRead
60
+ permissions += 'allowRead '
61
+ else
62
+ permissions += ' '
63
+ end
64
+
65
+ if @modifyAllRecords
66
+ permissions += 'modifyAllRecords '
67
+ else
68
+ permissions += ' '
69
+ end
70
+
71
+ if @viewAllRecords
72
+ permissions += 'viewAllRecords'
73
+ else
74
+ permissions += ' '
75
+ end
76
+
77
+ permissions
78
+ end
79
+
19
80
  end
20
81
 
21
82
  # See https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_profile.htm#profileobjectpermissions_title
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Burwell