Esempio n. 1
0
        protected virtual bool HasRights(ChoiceActionItem item, IModelView view)
        {
            var data = (ViewShortcut)item.Data;

            if (view == null)
            {
                throw new ArgumentException(string.Format("Cannot find the '{0}' view specified by the shortcut: {1}",
                                                          data.ViewId, data));
            }
            Type type = (view is IModelObjectView) ? ((IModelObjectView)view).ModelClass.TypeInfo.Type : null;

            if (type != null)
            {
                if (!string.IsNullOrEmpty(data.ObjectKey) && !data.ObjectKey.StartsWith("@"))
                {
                    try {
                        using (IObjectSpace space = CreateObjectSpace()) {
                            object objectByKey = space.GetObjectByKey(type, space.GetObjectKey(type, data.ObjectKey));
                            return(DataManipulationRight.CanRead(type, null, objectByKey, null, space) &&
                                   DataManipulationRight.CanNavigate(type, objectByKey, space));
                        }
                    } catch {
                        return(true);
                    }
                }
                return(DataManipulationRight.CanNavigate(type, null, null));
            }
            return(true);
        }
        protected virtual bool HasRights(ChoiceActionItem item, IModelView view)
        {
            var data = (ViewShortcut)item.Data;

            if (view == null)
            {
                if (Application.GetPlatform() == Platform.Win)
                {
                    throw new ArgumentException($"Cannot find the '{data.ViewId}' view specified by the shortcut: {data}");
                }

                var webApi = Application.WhenWeb().Wait();
                webApi.Redirect(webApi.GetRequestUri().GetLeftPart(UriPartial.Authority));
            }
            var  objectView = view as IModelObjectView;
            Type type       = objectView?.ModelClass.TypeInfo.Type;

            if (type != null)
            {
                if (!string.IsNullOrEmpty(data.ObjectKey) && !data.ObjectKey.StartsWith("@"))
                {
                    try {
                        using IObjectSpace space = CreateObjectSpace();
                        object objectByKey = space.GetObjectByKey(type, space.GetObjectKey(type, data.ObjectKey));
                        return(DataManipulationRight.CanRead(type, null, objectByKey, null, space) &&
                               DataManipulationRight.CanNavigate(type, objectByKey, space));
                    }
                    catch {
                        return(true);
                    }
                }
                return(DataManipulationRight.CanNavigate(type, null, null));
            }
            return(true);
        }