drakkan / sftpgo
Showing 1 of 7 files from the diff.

@@ -628,8 +628,8 @@
Loading
628 628
	return err
629 629
}
630 630
631 -
func getUserForEventAction(username string) (dataprovider.User, error) {
632 -
	user, err := dataprovider.GetUserWithGroupSettings(username)
631 +
func getUserForEventAction(user dataprovider.User) (dataprovider.User, error) {
632 +
	err := user.LoadAndApplyGroupSettings()
633 633
	if err != nil {
634 634
		return dataprovider.User{}, err
635 635
	}
@@ -649,8 +649,8 @@
Loading
649 649
	return conn.RemoveFile(fs, fsPath, item, info)
650 650
}
651 651
652 -
func executeDeleteFsAction(deletes []string, replacer *strings.Replacer, username string) error {
653 -
	user, err := getUserForEventAction(username)
652 +
func executeDeleteFsActionForUser(deletes []string, replacer *strings.Replacer, user dataprovider.User) error {
653 +
	user, err := getUserForEventAction(user)
654 654
	if err != nil {
655 655
		return err
656 656
	}
@@ -684,8 +684,40 @@
Loading
684 684
	return nil
685 685
}
686 686
687 -
func executeMkDirsFsAction(dirs []string, replacer *strings.Replacer, username string) error {
688 -
	user, err := getUserForEventAction(username)
687 +
func executeDeleteFsRuleAction(deletes []string, replacer *strings.Replacer,
688 +
	conditions dataprovider.ConditionOptions, params EventParams,
689 +
) error {
690 +
	users, err := params.getUsers()
691 +
	if err != nil {
692 +
		return fmt.Errorf("unable to get users: %w", err)
693 +
	}
694 +
	var failures []string
695 +
	executed := 0
696 +
	for _, user := range users {
697 +
		// if sender is set, the conditions have already been evaluated
698 +
		if params.sender == "" && !checkEventConditionPatterns(user.Username, conditions.Names) {
699 +
			eventManagerLog(logger.LevelDebug, "skipping fs delete for user %s, name conditions don't match",
700 +
				user.Username)
701 +
			continue
702 +
		}
703 +
		executed++
704 +
		if err = executeDeleteFsActionForUser(deletes, replacer, user); err != nil {
705 +
			failures = append(failures, user.Username)
706 +
			continue
707 +
		}
708 +
	}
709 +
	if len(failures) > 0 {
710 +
		return fmt.Errorf("fs delete failed for users: %+v", failures)
711 +
	}
712 +
	if executed == 0 {
713 +
		eventManagerLog(logger.LevelError, "no delete executed")
714 +
		return errors.New("no delete executed")
715 +
	}
716 +
	return nil
717 +
}
718 +
719 +
func executeMkDirsFsActionForUser(dirs []string, replacer *strings.Replacer, user dataprovider.User) error {
720 +
	user, err := getUserForEventAction(user)
689 721
	if err != nil {
690 722
		return err
691 723
	}
@@ -709,8 +741,42 @@
Loading
709 741
	return nil
710 742
}
711 743
712 -
func executeRenameFsAction(renames []dataprovider.KeyValue, replacer *strings.Replacer, username string) error {
713 -
	user, err := getUserForEventAction(username)
744 +
func executeMkdirFsRuleAction(dirs []string, replacer *strings.Replacer,
745 +
	conditions dataprovider.ConditionOptions, params EventParams,
746 +
) error {
747 +
	users, err := params.getUsers()
748 +
	if err != nil {
749 +
		return fmt.Errorf("unable to get users: %w", err)
750 +
	}
751 +
	var failures []string
752 +
	executed := 0
753 +
	for _, user := range users {
754 +
		// if sender is set, the conditions have already been evaluated
755 +
		if params.sender == "" && !checkEventConditionPatterns(user.Username, conditions.Names) {
756 +
			eventManagerLog(logger.LevelDebug, "skipping fs mkdir for user %s, name conditions don't match",
757 +
				user.Username)
758 +
			continue
759 +
		}
760 +
		executed++
761 +
		if err = executeMkDirsFsActionForUser(dirs, replacer, user); err != nil {
762 +
			failures = append(failures, user.Username)
763 +
			continue
764 +
		}
765 +
	}
766 +
	if len(failures) > 0 {
767 +
		return fmt.Errorf("fs mkdir failed for users: %+v", failures)
768 +
	}
769 +
	if executed == 0 {
770 +
		eventManagerLog(logger.LevelError, "no mkdir executed")
771 +
		return errors.New("no mkdir executed")
772 +
	}
773 +
	return nil
774 +
}
775 +
776 +
func executeRenameFsActionForUser(renames []dataprovider.KeyValue, replacer *strings.Replacer,
777 +
	user dataprovider.User,
778 +
) error {
779 +
	user, err := getUserForEventAction(user)
714 780
	if err != nil {
715 781
		return err
716 782
	}
@@ -732,17 +798,51 @@
Loading
732 798
	return nil
733 799
}
734 800
735 -
func executeFsRuleAction(c dataprovider.EventActionFilesystemConfig, params EventParams) error {
801 +
func executeRenameFsRuleAction(renames []dataprovider.KeyValue, replacer *strings.Replacer,
802 +
	conditions dataprovider.ConditionOptions, params EventParams,
803 +
) error {
804 +
	users, err := params.getUsers()
805 +
	if err != nil {
806 +
		return fmt.Errorf("unable to get users: %w", err)
807 +
	}
808 +
	var failures []string
809 +
	executed := 0
810 +
	for _, user := range users {
811 +
		// if sender is set, the conditions have already been evaluated
812 +
		if params.sender == "" && !checkEventConditionPatterns(user.Username, conditions.Names) {
813 +
			eventManagerLog(logger.LevelDebug, "skipping fs rename for user %s, name conditions don't match",
814 +
				user.Username)
815 +
			continue
816 +
		}
817 +
		executed++
818 +
		if err = executeRenameFsActionForUser(renames, replacer, user); err != nil {
819 +
			failures = append(failures, user.Username)
820 +
			continue
821 +
		}
822 +
	}
823 +
	if len(failures) > 0 {
824 +
		return fmt.Errorf("fs rename failed for users: %+v", failures)
825 +
	}
826 +
	if executed == 0 {
827 +
		eventManagerLog(logger.LevelError, "no rename executed")
828 +
		return errors.New("no rename executed")
829 +
	}
830 +
	return nil
831 +
}
832 +
833 +
func executeFsRuleAction(c dataprovider.EventActionFilesystemConfig, conditions dataprovider.ConditionOptions,
834 +
	params EventParams,
835 +
) error {
736 836
	addObjectData := false
737 837
	replacements := params.getStringReplacements(addObjectData)
738 838
	replacer := strings.NewReplacer(replacements...)
739 839
	switch c.Type {
740 840
	case dataprovider.FilesystemActionRename:
741 -
		return executeRenameFsAction(c.Renames, replacer, params.sender)
841 +
		return executeRenameFsRuleAction(c.Renames, replacer, conditions, params)
742 842
	case dataprovider.FilesystemActionDelete:
743 -
		return executeDeleteFsAction(c.Deletes, replacer, params.sender)
843 +
		return executeDeleteFsRuleAction(c.Deletes, replacer, conditions, params)
744 844
	case dataprovider.FilesystemActionMkdirs:
745 -
		return executeMkDirsFsAction(c.MkDirs, replacer, params.sender)
845 +
		return executeMkdirFsRuleAction(c.MkDirs, replacer, conditions, params)
746 846
	default:
747 847
		return fmt.Errorf("unsupported filesystem action %d", c.Type)
748 848
	}
@@ -953,7 +1053,7 @@
Loading
953 1053
	case dataprovider.ActionTypeDataRetentionCheck:
954 1054
		return executeDataRetentionCheckRuleAction(action.Options.RetentionConfig, conditions, params)
955 1055
	case dataprovider.ActionTypeFilesystem:
956 -
		return executeFsRuleAction(action.Options.FsConfig, params)
1056 +
		return executeFsRuleAction(action.Options.FsConfig, conditions, params)
957 1057
	default:
958 1058
		return fmt.Errorf("unsupported action type: %d", action.Type)
959 1059
	}
@@ -1070,10 +1170,6 @@
Loading
1070 1170
		eventManagerLog(logger.LevelError, "unable to load rule with name %q", j.ruleName)
1071 1171
		return
1072 1172
	}
1073 -
	if err = rule.CheckActionsConsistency(""); err != nil {
1074 -
		eventManagerLog(logger.LevelWarn, "scheduled rule %q skipped: %v", rule.Name, err)
1075 -
		return
1076 -
	}
1077 1173
	task, err := j.getTask(rule)
1078 1174
	if err != nil {
1079 1175
		return
Files Coverage
internal 99.57%
Project Totals (72 files) 99.57%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading