Esempio n. 1
0
        public PermissionResult CanMarkInactive(Login login)
        {
            if (login == null)
            {
                throw new ArgumentNullException("login");
            }

            // Check if the item isn't already inactive
            var isInactive = !login.IsActive;

            if (isInactive)
            {
                return(PermissionResult.Deny(this.Settings.LoginIsAlreadyInactiveMsg));
            }

            // Check if we have other message which is critical and it isn't handled
            var isSystem = this.IsSystem(login);

            if (isSystem)
            {
                return(PermissionResult.Deny(this.Settings.LoginIsSystemMsg));
            }

            return(PermissionResult.Allow);
        }
Esempio n. 2
0
        public Task ShowMessageAsync(LocalizationKey localizationKey)
        {
            if (localizationKey == null)
            {
                throw new ArgumentNullException(nameof(localizationKey));
            }

            return(this.GetService <IModalDialog>().ShowAsync(PermissionResult.Deny(this.GetLocalized(localizationKey))));
        }
Esempio n. 3
0
        public static PermissionResult CanAddHeader(MainContext context, AgendaHeader header, IEnumerable <AgendaHeader> headers)
        {
            if (header == null)
            {
                throw new ArgumentNullException(nameof(header));
            }
            if (headers == null)
            {
                throw new ArgumentNullException(nameof(headers));
            }

            var result = Validator.ValidateNotEmpty(header.Name, @"HeaderNameIsRequired");

            if (result != PermissionResult.Allow)
            {
                return(result);
            }
            var name = (header.Name ?? string.Empty).Trim();

            foreach (var h in headers)
            {
                if (h.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
                {
                    return(PermissionResult.Deny(@"HeaderWithTheSameNameAlreadyExists"));
                }
            }
            var values = GetData(context);

            //context.Log(nameof(IsAgendaHeaderExists), LogLevel.Info);
            if (IsAgendaHeaderExists(values, name))
            {
                return(PermissionResult.Deny(@"HeaderWithTheSameNameAlreadyExists"));
            }
            var date = header.DateTime.Date;

            //context.Log(nameof(IsDateExists), LogLevel.Info);
            if (IsDateExists(values, date))
            {
                return(PermissionResult.Deny(@"HeaderWithTheSameDateAlreadyExists"));
            }
            // TODO : Parameter ???
            if (date < DateTime.Today.AddDays(-30))
            {
                return(PermissionResult.Confirm(@"HeaderDateConfirmTooOld"));
            }
            return(PermissionResult.Allow);
        }
Esempio n. 4
0
        public PermissionResult CanChangeStartTime(Activity activity, DateTime dateTime)
        {
            if (activity == null)
            {
                throw new ArgumentNullException(nameof(activity));
            }

            if (activity.Details == string.Empty)
            {
                return(PermissionResult.Deny(@"CannotChangeDateOfServerActivity"));
            }
            if (activity.Details == @"???")
            {
                return(PermissionResult.Confirm(@"OutsideOfWorkingHours"));
            }
            return(PermissionResult.Allow);
        }
Esempio n. 5
0
        //public PermissionResult CanCreate(Outlet outlet, ActivityType activityType)
        //{
        //	if (outlet == null)
        //	{
        //		return PermissionResult.Deny(@"MissingOutlet");
        //	}
        //	if (activityType == null)
        //	{
        //		return PermissionResult.Deny(@"MissingActivityType");
        //	}
        //	if (outlet.Id > 0 && activityType.Id > 0)
        //	{
        //		return PermissionResult.Confirm(@"Confirm activity type for this outlet?");
        //	}
        //	return PermissionResult.Allow;
        //}

        //public Activity Create(DataQueryContext context, Outlet outlet, ActivityType type, ActivityStatus status, DateTime date)
        //{
        //	if (context == null) throw new ArgumentNullException(nameof(context));
        //	if (type == null) throw new ArgumentNullException(nameof(type));
        //	if (status == null) throw new ArgumentNullException(nameof(status));
        //	if (outlet == null) throw new ArgumentNullException(nameof(outlet));

        //	var activity = new Activity(0, outlet, type, status, date, date, string.Empty);

        //	// Save activity to db
        //	var newActivity = this.DataProvider.Insert(context, activity);

        //	// Find item by outlet
        //	var agendaOutlet = default(AgendaOutlet);
        //	foreach (var o in this.Outlets)
        //	{
        //		if (o.Outlet == outlet)
        //		{
        //			agendaOutlet = o;
        //			break;
        //		}
        //	}
        //	// We don't have it
        //	if (agendaOutlet == null)
        //	{
        //		// Create it
        //		agendaOutlet = new AgendaOutlet(outlet, new List<Activity>());

        //		// Add to the collection
        //		this.Outlets.Add(agendaOutlet);
        //	}

        //	// Insert into the collection
        //	agendaOutlet.Activities.Add(newActivity);

        //	this.ActivityAdded?.Invoke(this, new ActivityEventArgs(newActivity));

        //	return newActivity;
        //}

        public PermissionResult CanCancel(Activity activity, ActivityCancelReason cancelReason)
        {
            if (activity == null)
            {
                throw new ArgumentNullException(nameof(activity));
            }

            if (activity.Status == null)
            {
                return(PermissionResult.Deny(@"CannotCancelInactiveActivity"));
            }
            // Check the day
            // TODO : !!!
            //var visitDay = this.DataProvider.GetVisitDay(DateTime.Today);

            return(PermissionResult.Allow);
        }
Esempio n. 6
0
        public PermissionResult CanAdd(Login login)
        {
            if (login == null)
            {
                throw new ArgumentNullException("login");
            }

            // Trim the username
            var username = (login.Username ?? string.Empty).Trim();

            if (this.IsSystem(login))
            {
                return(PermissionResult.Deny(this.Settings.UsernameIsReservedForInternalUseMsg));
            }

            // Check for duplicate username
            // Check in the database ?!?? Do we need the field ?!
            foreach (var current in _logins)
            {
                if (current.Username.Equals(username, StringComparison.OrdinalIgnoreCase))
                {
                    return(PermissionResult.Deny(this.Settings.UsernameAlreadyTakenMsg));
                }
            }

            // Check password strength
            var strength = GetPasswordStrength(login.Password);

            switch (strength)
            {
            case PasswordStrength.Weak:
                return(PermissionResult.Deny(this.Settings.PasswordTooWeakMsg));

            case PasswordStrength.Medium:
                return(PermissionResult.Confirm(this.Settings.ConfirmPasswordMediumStrengthMsg));

            case PasswordStrength.Good:
            case PasswordStrength.Strong:
                return(PermissionResult.Allow);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 7
0
 private static PermissionResult CanCreateActivityForOutlet(Feature f)
 {
     {
         {
             var assignment = "From the for outlet";
             if (assignment == null)
             {
                 // TODO : Display message
                 return(PermissionResult.Deny("No outlet assignment"));
             }
             var hasAssignment = assignment.Length > 0;
             if (!hasAssignment)
             {
                 // TODO : Display message
                 return(PermissionResult.Deny("Invalid assignment"));
             }
         }
         //Is R E D Activities Allowed
         {
             // TODO : !!!
             return(PermissionResult.Allow);
         }
     }
 }