16 using System.Collections.Generic;
19 using erminas.SmartAPI.CMS.Project.ContentClasses.Elements;
20 using erminas.SmartAPI.CMS.Project.Pages;
21 using erminas.SmartAPI.CMS.Project.Pages.Elements;
22 using erminas.SmartAPI.CMS.ServerManagement;
23 using erminas.SmartAPI.Exceptions;
24 using erminas.SmartAPI.Utils;
25 using erminas.SmartAPI.Utils.CachedCollections;
27 namespace erminas.SmartAPI.CMS.Project.Authorizations
85 new string Name {
get;
set; }
89 void Rename(
string newName);
97 void CreateDetailForElement(
IPageElement pageElement,
string name);
99 void CreateDetailForLink(
ILinkElement link,
string name);
101 void CreateDetailForPage(
IPage page,
string name);
102 void CreateGlobal(
string name);
103 IIndexedCachedList<string, IAuthorizationPackage> ForElements {
get; }
104 IIndexedCachedList<string, IAuthorizationPackage> ForLinks {
get; }
105 IIndexedCachedList<string, IAuthorizationPackage> ForPages {
get; }
106 IIndexedCachedList<string, IAuthorizationPackage> Standard {
get; }
115 DetailedAssetManagerAttribute = 8,
119 LanguageVariant = 128
122 internal class AuthorizationPackages : IAuthorizationPackages
124 public AuthorizationPackages(
IProject project)
127 ForLinks =
new NameIndexedRDList<IAuthorizationPackage>(GetForLinks,
Caching.Enabled);
128 ForElements =
new NameIndexedRDList<IAuthorizationPackage>(GetForElements,
Caching.Enabled);
129 ForPages =
new NameIndexedRDList<IAuthorizationPackage>(GetForPages,
Caching.Enabled);
130 Standard =
new NameIndexedRDList<IAuthorizationPackage>(GetStandard,
Caching.Enabled);
133 public void CreateDetailForElement(
IPageElement pageElement,
string name)
136 ForElements.InvalidateCache();
142 ForElements.InvalidateCache();
145 public void CreateDetailForLink(
ILinkElement link,
string name)
148 ForLinks.InvalidateCache();
154 ForLinks.InvalidateCache();
158 public void CreateDetailForPage(
IPage page,
string name)
161 ForPages.InvalidateCache();
164 public void CreateGlobal(
string name)
166 const string CREATE =
167 @"<AUTHORIZATION><AUTHORIZATIONPACKET action=""addnew"" name=""{0}""/></AUTHORIZATION>";
168 var answer = Project.ExecuteRQL(CREATE.RQLFormat(name));
169 CheckAnswer(name, answer);
172 public IIndexedCachedList<string, IAuthorizationPackage> ForElements {
get;
private set; }
173 public IIndexedCachedList<string, IAuthorizationPackage> ForLinks {
get;
private set; }
174 public IIndexedCachedList<string, IAuthorizationPackage> ForPages {
get;
private set; }
175 public IProject Project {
get;
private set; }
177 public ISession Session
179 get {
return Project.Session; }
182 public IIndexedCachedList<string, IAuthorizationPackage> Standard {
get;
private set; }
184 private void CheckAnswer(
string name, XmlDocument answer)
188 var element = answer.GetSingleElement(
"AUTHORIZATIONPACKET");
189 if (element.GetName() != name)
192 string.Format(
"Could not create authorizationpackage {0}", name));
197 string.Format(
"Could not create authorizationpackage {0}", name), e);
201 private void CreateDetail(
string elementtype, IRedDotObject obj,
string name,
AuthorizationType type)
203 const string CREATE =
204 @"<AUTHORIZATION><{0} guid=""{1}><AUTHORIZATIONPACKET action=""addnew"" name=""{2}"" guid="" type=""{3}""/></{0}></AUTHORIZATION>";
206 string query = CREATE.RQLFormat(elementtype, obj, name, (
int) type);
208 var answer = Project.ExecuteRQL(query);
209 CheckAnswer(name, answer);
210 Standard.InvalidateCache();
213 private List<IAuthorizationPackage> GetAuthorizationPackages(
AuthorizationType type)
215 const string LIST_PACKAGES =
216 @"<AUTHORIZATION><AUTHORIZATIONS action=""list"" type=""{0}""/></AUTHORIZATION>";
217 var xmlDoc = Project.ExecuteRQL(LIST_PACKAGES.RQLFormat((
int) type));
219 return (from XmlElement curelement in xmlDoc.GetElementsByTagName(
"AUTHORIZATION")
220 select (IAuthorizationPackage) new AuthorizationPackage(Project, curelement)).ToList();
223 private List<IAuthorizationPackage> GetForElements()
228 private List<IAuthorizationPackage> GetForLinks()
233 private List<IAuthorizationPackage> GetForPages()
238 private List<IAuthorizationPackage> GetStandard()
244 internal class AuthorizationPackage : RedDotProjectObject, IAuthorizationPackage
246 public AuthorizationPackage(IProject project, XmlElement xmlElement) : base(project, xmlElement)
248 Type = xmlElement.GetIntAttributeValue(
"type").GetValueOrDefault();
249 GroupAuthorizations =
new GroupAuthorizations(
this,
Caching.Enabled);
250 UserAuthorizations =
new UserAuthorizations(
this,
Caching.Enabled);
255 const string SAVE_NAME =
256 @"<AUTHORIZATION><AUTHORIZATIONPACKET action=""save"" guid=""{0}"" name=""{1}""/></AUTHORIZATION>";
257 Project.ExecuteRQL(SAVE_NAME.RQLFormat(
this, Name));
260 public IGroupAuthorizations GroupAuthorizations {
get;
private set; }
261 public new string Name {
get {
return base.Name; }
set { base.Name = value; } }
263 public void Rename(
string newName)
269 public int Type {
get;
private set; }
271 public IUserAuthorizations UserAuthorizations {
get;
private set; }
274 internal class GroupAuthorizations : IndexedCachedList<string, IGroupAuthorization>, IGroupAuthorizations
276 private readonly IAuthorizationPackage _package;
278 public GroupAuthorizations(IAuthorizationPackage package,
Caching caching)
279 : base(authorization => authorization.Group.Name, caching)
282 RetrieveFunc = GetAuthorizations;
285 public IGroupAuthorization CreateFor(
IGroup @group)
287 return new GroupAuthorizationRights(_package, group);
290 private List<IGroupAuthorization> GetAuthorizations()
292 const string LOAD_AUTH =
293 @"<AUTHORIZATION><AUTHORIZATIONPACKET action=""load"" guid=""{0}""/></AUTHORIZATION>";
295 var xmlDoc = _package.Project.ExecuteRQL(LOAD_AUTH.RQLFormat(_package));
298 return (from XmlElement curElement in xmlDoc.GetElementsByTagName(
"GROUP")
299 where _package.Project.AssignedGroups.TryGetByGuid(curElement.GetGuid(), out curGroup)
300 select (IGroupAuthorization)
new GroupAuthorizationRights(_package, curGroup, curElement)).ToList();
304 internal class UserAuthorizations : IndexedCachedList<string, IUserAuthorization>, IUserAuthorizations
306 private readonly IAuthorizationPackage _package;
308 public UserAuthorizations(IAuthorizationPackage package,
Caching caching)
309 : base(authorization => authorization.User.Name, caching)
312 RetrieveFunc = GetAuthorizations;
315 public IUserAuthorization CreateFor(
IUser @group)
317 return new UserAuthorizationRights(_package, group);
320 private List<IUserAuthorization> GetAuthorizations()
322 const string LOAD_AUTH =
323 @"<AUTHORIZATION><AUTHORIZATIONPACKET action=""load"" guid=""{0}""/></AUTHORIZATION>";
325 var xmlDoc = _package.Project.ExecuteRQL(LOAD_AUTH.RQLFormat(_package));
328 return (from XmlElement curElement in xmlDoc.GetElementsByTagName(
"USER")
329 where _package.Project.Users.TryGetByUserGuid(curElement.GetGuid(), out curUser)
330 select (IUserAuthorization)
new UserAuthorizationRights(_package, curUser.
User, curElement)).ToList();
339 int DeniedAssetManagerAttributeRights {
get;
set; }
340 int DeniedAssetManagerFolderRights {
get;
set; }
341 int DeniedContentClassRights {
get;
set; }
343 int DeniedElementRights {
get;
set; }
344 int DeniedGlobalRights {
get;
set; }
345 int DeniedPageRights {
get;
set; }
346 int DeniedProjectOrLanguageVariantRights {
get;
set; }
348 int DeniedStructuralElementRights {
get;
set; }
350 int GrantedAssetManagerAttributeRights {
get;
set; }
351 int GrantedAssetManagerFolderRights {
get;
set; }
353 int GrantedContentClassRights {
get;
set; }
354 int GrantedElementRights {
get;
set; }
356 int GrantedGlobalRights {
get;
set; }
357 int GrantedPageRights {
get;
set; }
358 int GrantedProjectOrLanguageVariantRights {
get;
set; }
359 int GrantedStructuralElementRights {
get;
set; }
387 internal abstract class AuthorizationRights : IAuthorizationRights
389 private readonly IAuthorizationPackage _package;
391 public AuthorizationRights(IAuthorizationPackage package, XmlElement element)
395 GrantedPageRights = element.GetIntAttributeValue(
"right1").GetValueOrDefault();
396 DeniedPageRights = element.GetIntAttributeValue(
"deny1").GetValueOrDefault();
398 GrantedStructuralElementRights = element.GetIntAttributeValue(
"right2").GetValueOrDefault();
399 DeniedStructuralElementRights = element.GetIntAttributeValue(
"deny2").GetValueOrDefault();
401 GrantedElementRights = element.GetIntAttributeValue(
"right3").GetValueOrDefault();
402 DeniedElementRights = element.GetIntAttributeValue(
"deny3").GetValueOrDefault();
404 GrantedGlobalRights = element.GetIntAttributeValue(
"right4").GetValueOrDefault();
405 DeniedGlobalRights = element.GetIntAttributeValue(
"deny4").GetValueOrDefault();
407 GrantedAssetManagerAttributeRights = element.GetIntAttributeValue(
"right5").GetValueOrDefault();
408 DeniedAssetManagerAttributeRights = element.GetIntAttributeValue(
"deny5").GetValueOrDefault();
410 GrantedContentClassRights = element.GetIntAttributeValue(
"right6").GetValueOrDefault();
411 DeniedContentClassRights = element.GetIntAttributeValue(
"deny6").GetValueOrDefault();
413 GrantedProjectOrLanguageVariantRights = element.GetIntAttributeValue(
"right7").GetValueOrDefault();
414 DeniedProjectOrLanguageVariantRights = element.GetIntAttributeValue(
"deny7").GetValueOrDefault();
416 GrantedAssetManagerFolderRights = element.GetIntAttributeValue(
"right8").GetValueOrDefault();
417 DeniedAssetManagerFolderRights = element.GetIntAttributeValue(
"deny8").GetValueOrDefault();
420 protected AuthorizationRights(IAuthorizationPackage package)
425 public IAuthorizationPackage AuthorizationPackage
427 get {
return _package; }
430 public abstract void Commit();
431 public int DeniedAssetManagerAttributeRights {
get;
set; }
432 public int DeniedAssetManagerFolderRights {
get;
set; }
433 public int DeniedContentClassRights {
get;
set; }
434 public int DeniedElementRights {
get;
set; }
435 public int DeniedGlobalRights {
get;
set; }
436 public int DeniedPageRights {
get;
set; }
437 public int DeniedProjectOrLanguageVariantRights {
get;
set; }
438 public int DeniedStructuralElementRights {
get;
set; }
439 public int GrantedAssetManagerAttributeRights {
get;
set; }
440 public int GrantedAssetManagerFolderRights {
get;
set; }
441 public int GrantedContentClassRights {
get;
set; }
442 public int GrantedElementRights {
get;
set; }
443 public int GrantedGlobalRights {
get;
set; }
444 public int GrantedPageRights {
get;
set; }
445 public int GrantedProjectOrLanguageVariantRights {
get;
set; }
446 public int GrantedStructuralElementRights {
get;
set; }
448 public IProject Project
450 get {
return _package.Project; }
453 public ISession Session
455 get {
return _package.Session; }
459 internal class UserAuthorizationRights : AuthorizationRights, IUserAuthorization
461 public UserAuthorizationRights(IAuthorizationPackage package,
IUser user, XmlElement element)
462 : base(package, element)
467 public UserAuthorizationRights(IAuthorizationPackage package,
IUser user) : base(package)
472 public override void Commit()
474 const string SAVE_USER_RIGHTS =
475 @"<AUTHORIZATION><AUTHORIZATIONPACKET action=""save"" guid=""{0}""><USERS><USER guid=""{1}"" right1=""{2}"" right2=""{3}"" right3=""{4}"" right4=""{5}"" right5=""{6}"" right6=""{7}"" right7=""{8}"" right8=""{9}"" deny1=""{10}"" deny2=""{11}"" deny3=""{12}"" deny4=""{13}"" deny5=""{14}"" deny6=""{15}"" deny7=""{16}"" deny8=""{17}""/></USERS></AUTHORIZATIONPACKET></AUTHORIZATION>";
477 string query = SAVE_USER_RIGHTS.RQLFormat(AuthorizationPackage, User, GrantedPageRights,
478 GrantedStructuralElementRights, GrantedElementRights,
479 GrantedGlobalRights, GrantedAssetManagerAttributeRights,
480 GrantedContentClassRights, GrantedProjectOrLanguageVariantRights,
481 GrantedAssetManagerFolderRights, DeniedPageRights,
482 DeniedStructuralElementRights, DeniedElementRights,
483 DeniedGlobalRights, DeniedAssetManagerAttributeRights,
484 DeniedContentClassRights, DeniedProjectOrLanguageVariantRights,
485 DeniedAssetManagerFolderRights);
487 Project.ExecuteRQL(query);
490 public IUser User {
get;
private set; }
493 internal class GroupAuthorizationRights : AuthorizationRights, IGroupAuthorization
495 public GroupAuthorizationRights(IAuthorizationPackage package,
IGroup group, XmlElement element)
496 : base(package, element)
501 public GroupAuthorizationRights(IAuthorizationPackage package,
IGroup group) : base(package)
506 public override void Commit()
508 const string SAVE_GROUP_RIGHTS =
509 @"<AUTHORIZATION><AUTHORIZATIONPACKET action=""save"" guid=""{0}""><GROUPS><GROUP guid=""{1}"" right1=""{2}"" right2=""{3}"" right3=""{4}"" right4=""{5}"" right5=""{6}"" right6=""{7}"" right7=""{8}"" right8=""{9}"" deny1=""{10}"" deny2=""{11}"" deny3=""{12}"" deny4=""{13}"" deny5=""{14}"" deny6=""{15}"" deny7=""{16}"" deny8=""{17}""/></GROUPS></AUTHORIZATIONPACKET></AUTHORIZATION>";
511 string query = SAVE_GROUP_RIGHTS.RQLFormat(AuthorizationPackage, Group, GrantedPageRights,
512 GrantedStructuralElementRights, GrantedElementRights,
513 GrantedGlobalRights, GrantedAssetManagerAttributeRights,
514 GrantedContentClassRights, GrantedProjectOrLanguageVariantRights,
515 GrantedAssetManagerFolderRights, DeniedPageRights,
516 DeniedStructuralElementRights, DeniedElementRights,
517 DeniedGlobalRights, DeniedAssetManagerAttributeRights,
518 DeniedContentClassRights, DeniedProjectOrLanguageVariantRights,
519 DeniedAssetManagerFolderRights);
521 Project.ExecuteRQL(query);
524 public IGroup Group {
get;
private set; }